問題描述
我正在嘗試在 HPC 服務器上創(chuàng)建自己的 conda python 環(huán)境,但發(fā)生了一些非常奇怪的事情.
I am trying to make my own conda python environment on HPC server, and something very strange is happening.
問題
創(chuàng)建一個新的 conda 環(huán)境后,python 似乎沒有在這個環(huán)境中看到自己,并且正在使用 base 環(huán)境......因此我無法使用安裝在新環(huán)境中的包,但我可以看到 base 中的包環(huán)境...
After creating a new conda environment, it appears that python is not seeing itself in this environment, and using the base environment... Thus I cannot use packages installed in the new environment, but I can see the ones in the base environment...
這就是我所做的
我的環(huán)境安裝如下:
$ conda create -n niml pip python=3.6.5
$ source activate niml
(niml) $ conda install -c conda-forge luigi
然后我檢查我安裝的包:
and then I check my installed packages:
(niml) $ conda list
這是我得到的,非?;镜沫h(huán)境:
and here is what I get, very basic environment:
# Name Version Build Channel
botocore 1.10.61 py_0 conda-forge
ca-certificates 2018.4.16 0 conda-forge
certifi 2018.4.16 py36_0 conda-forge
docutils 0.14 py36_0 conda-forge
jmespath 0.9.3 py_1 conda-forge
libedit 3.1.20170329 h6b74fdf_2
libffi 3.2.1 hd88cf55_4
libgcc-ng 7.2.0 hdf63c60_3
libstdcxx-ng 7.2.0 hdf63c60_3
lockfile 0.12.2 py_1 conda-forge
luigi 2.7.6 py36_0 conda-forge
ncurses 6.1 hf484d3e_0
openssl 1.0.2o 0 conda-forge
pip 10.0.1 py36_0
pyparsing 2.2.0 py_1 conda-forge
python 3.6.5 hc3d631a_2
python-daemon 2.1.2 py36_0
python-dateutil 2.7.3 py_0 conda-forge
readline 7.0 ha6073c6_4
setuptools 39.2.0 py36_0
six 1.11.0 py36_1 conda-forge
sqlite 3.24.0 h84994c4_0
tk 8.6.7 hc745277_3
tornado 4.5.3 py36_0 conda-forge
wheel 0.31.1 py36_0
xz 5.2.4 h14c3975_4
zlib 1.2.11 ha838bed_2
然后我嘗試運行python并導入我安裝的包luigi
,它沒有發(fā)現(xiàn)錯誤.
then I try running python and import the package which I installed luigi
, and it does not find it getting an error.
(niml) $ python
>>> import luigi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'luigi'
我還嘗試導入位于基礎環(huán)境中而不是在新環(huán)境中的 numpy
,它可以正常工作.
I also tried to import numpy
which is in the base environment and NOT in the new environment, and it works.
>>> import numpy
上面的工作,這意味著 python
認為它是在基礎環(huán)境中運行的.
The above works, which means python
thinks it is running in the base environment.
Python 正在我自己的環(huán)境中運行
查看了執(zhí)行的是哪個python,確實是新環(huán)境下的那個niml
:
I checked which python is being executed, and it is indeed the one in the new environment niml
:
>>> import sys
>>> sys.executable
'~/.conda/envs/niml/bin/python'
同樣從命令行檢查,它是環(huán)境中的 python
可執(zhí)行文件:
Also checked from the command line, and it is the python
executable within the envrinment:
(niml) $ which python
~/.conda/envs/niml/bin/python
我在 HPC 上運行
我之前已經(jīng)創(chuàng)建了數(shù)百次 anaconda 環(huán)境,但從未遇到過這個問題.唯一的區(qū)別是我使用的是 HPC 服務器,因此我必須做這樣的事情:
I have created anaconda environments hundreds of times before and never had this problem. Only difference is that I am using an HPC server, and thus I had to make something like this:
module load python/anaconda3
這是我從通常的工作流程中看到的唯一可能導致此問題的不同...
this is the only difference I see from my usual workflow which might be creating this problem...
其他人以前見過這個問題并且能夠解決它嗎??
Anyone else has seen this problem before and able to solve it??
推薦答案
我試圖解決一個類似的問題,并通過 virtualenv 而不是使用 conda 環(huán)境解決了這個問題.我相信 Anaconda 和您的機器之間存在沖突,因為兩者都認為他們正在控制您的新環(huán)境,而在 virtualenv 中設置新環(huán)境似乎可以解決問題.
I was trying to solve a similar issue and solved this through virtualenv rather than using a conda environment. I believe there is a conflict between Anaconda and your machine in that both think they are controlling your new environment which setting up a new environment in virtualenv seemed to fix.
如果有幫助,這里是如何使用 virtualenv 設置環(huán)境的方法.如果您還沒有位置,請為您的新環(huán)境創(chuàng)建一個位置:
If it's helpful, here's how to set up an environment using virtualenv. Create a location for your new environment if you don't have one already:
mkdir ~/virtualenvironment
設置您的虛擬環(huán)境:
virtualenv ~/virtualenvironment/niml/ --python=python3.6.5
激活您的環(huán)境:
source bin/activate
確保您已安裝所需的任何軟件包:
Make sure that you've installed whatever packages you need:
pip install luigi
檢查包是否在python中正確導入:
Check that the package imports properly in python:
python
import luigi
停用:
source deactivate
這篇關于無法導入安裝在新 Conda 環(huán)境中的軟件包的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!