I have a conda environment, in a bash terminal, with an Intel Python Distribution interpreter. However, when importing packages, they are imported from what looks to be the user directory of the system default Python, not the environment. Take a look at the version discrepancy and the __spec__ origin of the pandas package.
~ $ conda activate idp
~ $ which python
~/anaconda3/envs/idp/bin/python
~ $ python
Python 3.6.8 |Intel Corporation| (default, Mar 1 2019, 00:10:45)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import pandas
>>> pandas.__version__
'0.22.0'
>>> pandas.__spec__
ModuleSpec(name='pandas', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f509e184ba8>, origin='/home/torstein/.local/lib/python3.6/site-packages/pandas/__init__.py', submodule_search_locations=['/home/torstein/.local/lib/python3.6/site-packages/pandas'])
>>>
~ $ conda list | head -n 3
# packages in environment at /home/torstein/anaconda3/envs/idp:
#
# Name Version Build Channel
~ $ conda list | grep pandas
pandas 0.24.1 py36_3 intel
~ $ conda env list
# conda environments:
#
base /home/torstein/anaconda3
idp * /home/torstein/anaconda3/envs/idp
py36 /home/torstein/anaconda3/envs/py36
When using the base environment, this does NOT happen; packages (e.g. pandas) are imported from the correct path:
~ $ conda deactivate
~ $ conda env list
# conda environments:
#
base * /home/torstein/anaconda3
idp /home/torstein/anaconda3/envs/idp
py36 /home/torstein/anaconda3/envs/py36
~ $ which python
~/anaconda3/bin/python
~ $ python
Python 3.7.0 (default, Oct 9 2018, 10:31:47)
[GCC 7.3.0] :: Anaconda custom (64-bit) on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
pan>>> pandas.__version__
'0.23.4'
>>> pandas.__spec__
ModuleSpec(name='pandas', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fad808a8e80>, origin='/home/torstein/anaconda3/lib/python3.7/site-packages/pandas/__init__.py', submodule_search_locations=['/home/torstein/anaconda3/lib/python3.7/site-packages/pandas'])
The relevant part of .bashrc (no anaconda explicitly set in path):
export PATH="/home/torstein/.cargo/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/intel/lib/intel64_lin:/opt/intel/compilers_and_libraries_2018.0.128/linux/mkl/lib/intel64_lin/"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/torstein/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/torstein/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/torstein/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/torstein/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
Which yields these $PATHs, for the base and idp envs respectively:
~ $ echo $PATH
/home/torstein/anaconda3/bin:/home/torstein/anaconda3/condabin:/home/torstein/.cargo/bin:/home/torstein/.cargo/bin:/home/torstein/anaconda3/bin:/home/torstein/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/torstein/.local/bin:/home/torstein/bin
~ $ conda activate idp
~ $ echo $PATH
/home/torstein/anaconda3/envs/idp/bin:/home/torstein/anaconda3/condabin:/home/torstein/.cargo/bin:/home/torstein/.cargo/bin:/home/torstein/anaconda3/bin:/home/torstein/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/torstein/.local/bin:/home/torstein/bin
The pandas that I do want to import is located here, where it should be:
/home/torstein/anaconda3/envs/idp/lib/python3.6/site-packages/pandas
/home/torstein/.local/lib/python3.6/is not explicitly included in$PATH. - tsornpipfor the py36 environment end up in/home/torstein/.local/lib/python3.6/site-packages/? Because there is no system-wide python 3.6 installation (but there was once upon a time). - tsorn/home/torstein/.local/bin, based on the site packages. I'd recreate the whole thing - most of the packages should be cached, so it shouldn't take long. However, you can try it without if you'd like; though, I expect that the dependency resolver has already set something in the idp env that points to the wrongsite-packages. - merv/home/torstein/.local/lib/python3.6/site-packages/directory (back it up first though just in case). No,pipin a Conda env should still be keeping within the env. Do you havePYTHONPATHset (when not in an activated env)? - mervPYTHONPATHis not set either inbaseoridp. I don't know if it's set before conda runs the automaticPATHmanipulation upon terminal startup. Deleting (or renaming)/.local/lib/python3.6/site-packages/did the trick. Creating a new env was not necessary. Thanks! - tsorn