This is a small lesson I learnt in the last days as I’m relatively new to managing my python environments with anaconda and started using it on different machines.
I’m developing a small piece of software which reads data from a table. It could be a csv file, but more conveniently is to read directly form a spreadsheet file, in these cases libreoffice spreadsheets, ods files.
There exists odfpy for that end – even when it has not been updated for some time. After a few small tweaks it does its work as it should on my primary computer. Using anaconda3 to manage my python environments I created on my other computer a supposedly identical environment – but did so by hand w/o exporting the environment information from my primary development computer.
Yet when running my piece of software it always resulted in the IPython console of spyder with
ImportError: No module named 'odf'
So… why? The package is installed. I started spyder – and get this error. Wondering whether it’s a peculiarity of spyder’s IPython, I started that environment’s normal python in the console – and noticed that my programme worked! Now, that’s something to work on, an indeed the called python interpreter is a different one:
(py36) planetmaker@aeolusmaximus-vortex:~/idltools/BNE$ which python
in the „real“ python in my environment vs. anaconda’s default:
In : import sys
In : sys.executable
Changing the interpreter in spyder’s setting didn’t have the desired effect – but I tried to install IPython and spyder in that py36 environment – and yes! They happily installed – and the then newly-installed and started spyder from inside that environment did not exhibit the issue with not finding the odf package!
1) proper use of anaconda’s environment export feature.
I could have avoided the whole issue, had I made use of it. Export your environment and import it on another by means of anaconda:
Old machine: conda list --explicit > spec-file
New machine: conda create --name myenv --file spec-file.txt
2) Always install spyder specifically in an environment.
Anaconda’s default spyder does not have access to all the same paths as a spyder installed in an environment