Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

python - 无法导入通过pip安装的模块(anaconda python)(Can't import module installed with pip (anaconda python))

I'm trying to use the ReadIM package with an anaconda environment (anaconda 4.7.12, python 3.8, pip 19.3.1), thus requiring me to use pip install readIM which succeeds, with the package found in conda list and pip list .

(我正在尝试在Anaconda环境(anaconda 4.7.12,python 3.8,pip 19.3.1)中使用ReadIM软件包,因此要求我使用成功的pip install readIM ,并在conda listpip list找到该软件包。)

I have read a lot of posts talking about using the correct python and pip paths, my python where shows only my anaconda path, where I ran conda install pip beforehand, and then pip -V shows my pip is in my conda path.

(我读过很多关于使用正确的python和pip路径的文章,我的python where仅显示我的anaconda路径,我事先在其中运行conda install pip ,然后pip -V显示我的pip在我的conda路径中。)

I have tried conda update --all and pip uninstall readIM .

(我尝试了conda update --allpip uninstall readIM 。)

I also read that it could be an issue with Jupyter notebook, hence in the conda command prompt I tried python then import readIM , which still gave me the same import error.

(我还阅读到Jupyter笔记本可能存在问题,因此在conda命令提示符下,我尝试了python然后import readIM ,仍然给了我同样的导入错误。)

As advised on the source page, I tried installing by running python setup.py build install / python setup.py install in the source directory, however this gave me an error

(根据源页面上的建议,我尝试通过在源目录中运行python setup.py build install / python setup.py install ,但这给了我一个错误)

cygwin TypeError: '>=' not supported between instances of 'NoneType' and 'str'

(cygwin TypeError:'NoneType'和'str'的实例之间不支持'> =')

I am at a loss, any ideas?

(我很茫然,有什么想法吗?)

Thanks, Mustafa.

(谢谢,穆斯塔法。)

UPDATE:

(更新:)

Managed to compile it from source successfully, but still get the same error:

(设法成功地从源代码编译了它,但仍然收到相同的错误:)

(base) C:>python -m pip install ReadIM-0.8.2.tar.gz Processing c:\readim-0.8.2.tar.gz Building wheels for collected packages: ReadIM Building wheel for ReadIM (setup.py) ... done Created wheel for ReadIM: filename=ReadIM-0.8.2-cp37-cp37m-win_amd64.whl size=219546 sha256=90f8960a6f1f80ae62dc18eab4bcd31fb2a6dfd7da364a5c15fc37e6e2ce0360 Stored in directory: C:\Users\mi4517\AppData\Local\pip\Cache\wheels\d6\a9\11\936e986255027bb654601b322a3431f9bcc3fde72ebb406835 Successfully built ReadIM Installing collected packages: ReadIM Successfully installed ReadIM-0.8.2

((基本)C:> python -m pip install ReadIM-0.8.2.tar.gz处理c:\ readim-0.8.2.tar.gz收集包的构建轮:ReadIM ReadIM构建轮(setup.py)。 ..完成为ReadIM创建了转盘:filename = ReadIM-0.8.2-cp37-cp37m-win_amd64.whl size = 219546 sha256 = 90f8960a6f1f80ae62dc18eab4bcd31fb2a6dfd7da364a5c15fc37e6e2ce0360存储在目录中:C:\ Apps \ ips \ pip d6 \ a9 \ 11 \ 936e986255027bb654601b322a3431f9bcc3fde72ebb406835成功构建ReadIM安装收集的软件包:ReadIM成功安装ReadIM-0.8.2)

(base) C:>python Python 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.

((基本)C:> python Python 3.7.5(默认,2019年10月31日,15:18:51)[MSC v.1916 64位(AMD64)] ::在Win32上的Anaconda,Inc.键入“ help”,“ copyright ”,“信用”或“许可证”以获取更多信息。)

import readIM Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'readIM'>

(导入readIM Traceback(最近一次调用):ModuleNotFoundError中的文件“”,第1行:没有名为“ readIM”的模块)

Following their instructions ( python setup.py build install then python setup.py test ) yields a successful build but a failed test:

(按照他们的指示( python setup.py build install然后python setup.py test )产生成功的构建但失败的测试:)

C:\ReadIM-0.8.2>python setup.py test Traceback (most recent call last): File "setup.py", line 41, in assert os.path.isdir(testFileDir) AssertionError

(C:\ ReadIM-0.8.2> python setup.py测试回溯(最近一次调用为最新):文件“ setup.py”,第41行,在断言os.path.isdir(testFileDir)中出现AssertionError)

SOLUTION

()

It was installing correctly, just that I was importing it incorrectly in Python.

(它安装正确,只是我在Python中错误地导入了它 。)

I was doing import readIM or import readim when it should be import ReadIM I did not know it was case sensitive!

(我是做import readIMimport readim当它应该是import ReadIM我不知道它是区分大小写的!)

Thank you for your help, apologies for the trivial mistake on my part.

(感谢您的帮助,对于我的小失误深表歉意。)

  ask by Mustafa Iqbal translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had faced a similar issue.

(我曾经遇到过类似的问题。)

With your conda environment activated, type

(激活conda环境后,键入)

which pip

Check if it shows the path to pip in your environment.

(检查它是否显示您环境中的点画路径。)

In my case, it was not.

(就我而言,事实并非如此。)

It was showing path to some other pip.

(它正在显示通往其他点的道路。)

So pip install was installing in that environment.

(所以pip install是在那个环境中安装的。)

To fix use the full path of pip, like below

(要修复,请使用pip的完整路径,如下所示)

~/anaconda3/envs/my_env/bin/pip install ... 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...