Reputation: 1027
I have different anaconda environments. When starting up one of them it seems as if sys.path
is still set to some totally wrong directory. Am I not understanding the concepts of environments correctly or is this an error concerning my anaconda setup?
My environments:
fabianwerner ~$ conda env list
# conda environments:
#
base * /Users/fabianwerner/anaconda3/anaconda3
my-rdkit-env /Users/fabianwerner/anaconda3/anaconda3/envs/my-rdkit-env
openpose /Users/fabianwerner/anaconda3/anaconda3/envs/openpose
fabianwerner ~$
I activate the environment 'openpose':
fabianwerner ~$ conda activate openpose
(openpose) fabianwerner ~$
I will try to import 'keras' so let us make sure that it is installed:
(openpose) fabianwerner ~$ pip list | grep -i keras
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Keras (2.2.4)
Keras-Applications (1.0.7)
Keras-Preprocessing (1.0.9)
You are using pip version 9.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(openpose) fabianwerner ~$
I start python and try to import keras:
(openpose) fabianwerner ~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'keras'
>>>
Let us check where python looks for modules:
>>> import sys
>>> print(sys.path)
['', '/Users/fabianwerner/anaconda3/anaconda3/envs/my-rdkit-env/lib/python36.zip', '/Users/fabianwerner/anaconda3/anaconda3/envs/my-rdkit-env/lib/python3.6', '/Users/fabianwerner/anaconda3/anaconda3/envs/my-rdkit-env/lib/python3.6/lib-dynload', '/Users/fabianwerner/.local/lib/python3.6/site-packages', '/Users/fabianwerner/anaconda3/anaconda3/envs/my-rdkit-env/lib/python3.6/site-packages']
>>>
so I activated the environment 'openpose' but it still looks for modules in the other (wrong!) environment 'my-rdkit-env'!
How to fix this?
EDIT:
I cannot see any obvious problem with the anaconda setup as conda info -a gives the right path:
(openpose) fabianwerner ~$ conda info -a
active environment : openpose
active env location : /Users/fabianwerner/anaconda3/anaconda3/envs/openpose
shell level : 2
user config file : /Users/fabianwerner/.condarc
populated config files :
conda version : 4.5.11
conda-build version : 3.15.1
python version : 3.7.0.final.0
base environment : /Users/fabianwerner/anaconda3/anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/osx-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/osx-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/osx-64
https://repo.anaconda.com/pkgs/pro/noarch
package cache : /Users/fabianwerner/anaconda3/anaconda3/pkgs
/Users/fabianwerner/.conda/pkgs
envs directories : /Users/fabianwerner/anaconda3/anaconda3/envs
/Users/fabianwerner/.conda/envs
platform : osx-64
user-agent : conda/4.5.11 requests/2.19.1 CPython/3.7.0 Darwin/17.7.0 OSX/10.13.6
UID:GID : 502:20
netrc file : None
offline mode : False
# conda environments:
#
base /Users/fabianwerner/anaconda3/anaconda3
my-rdkit-env /Users/fabianwerner/anaconda3/anaconda3/envs/my-rdkit-env
openpose * /Users/fabianwerner/anaconda3/anaconda3/envs/openpose
strokinat0r /Users/fabianwerner/anaconda3/anaconda3/envs/strokinat0r
sys.version: 3.7.0 (default, Jun 28 2018, 07:39:16)
...
sys.prefix: /Users/fabianwerner/anaconda3/anaconda3
sys.executable: /Users/fabianwerner/anaconda3/anaconda3/bin/python
conda location: /Users/fabianwerner/anaconda3/anaconda3/lib/python3.7/site-packages/conda
conda-build: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-build
conda-convert: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-convert
conda-develop: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-develop
conda-env: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-env
conda-index: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-index
conda-inspect: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-inspect
conda-metapackage: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-metapackage
conda-render: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-render
conda-server: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-server
conda-skeleton: /Users/fabianwerner/anaconda3/anaconda3/bin/conda-skeleton
user site dirs: ~/.local/lib/python3.6
CIO_TEST: <not set>
CONDA_DEFAULT_ENV: openpose
CONDA_EXE: /Users/fabianwerner/anaconda3/anaconda3/bin/conda
CONDA_PREFIX: /Users/fabianwerner/anaconda3/anaconda3/envs/openpose
CONDA_PREFIX_1: /Users/fabianwerner/anaconda3/anaconda3
CONDA_PROMPT_MODIFIER: (openpose)
CONDA_PYTHON_EXE: /Users/fabianwerner/anaconda3/anaconda3/bin/python
CONDA_ROOT: /Users/fabianwerner/anaconda3/anaconda3
CONDA_SHLVL: 2
PATH: /Users/fabianwerner/anaconda3/anaconda3/envs/openpose/bin:/Users/fabianwerner/anaconda3/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/GIMP-2.10.app/Contents/MacOS
REQUESTS_CA_BUNDLE: <not set>
SSL_CERT_FILE: <not set>
WARNING: could not import _license.show_info
# try:
# $ conda install -n root _license
(openpose) fabianwerner ~$
Also, I do not seem to have an environment variable set that relates to python:
(openpose) fabianwerner ~$ printenv | grep -i python
CONDA_PYTHON_EXE=/Users/fabianwerner/anaconda3/anaconda3/bin/python
(openpose) fabianwerner ~$
My setup:
Thanks,
FW
Upvotes: 1
Views: 3836
Reputation: 1400
The Python interpreter you started in your example is not the one in the environment.
conda info -a
says python version : 3.7.0.final.0
and yet your interpreter says Python 3.6.5
The problem should become apparent when you activate your environment and run which python
which should be pointing to the activated env but probably doesn't.
How did you create those environments? Make sure to set the python=XX
option or the new environment uses the interpreter from the base/root environment rather than installing a new one. I.e. conda create -n my_environment python=3.7
Edit:
Sorry, I just looked up and tested conda info -a
. python version : XX
seems to be referring to the base env not the currently active one.
I'm leaving this answer here, since even though my reasoning seems to be wrong, it may still be helpful.
Upvotes: 2