[英]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
.我正在尝试将ReadIM包与 anaconda 环境(anaconda 4.7.12、python 3.8、pip 19.3.1)一起使用,因此需要我使用成功的
pip install readIM
包,在conda list
和pip 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 --all
和pip 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 notebook 的问题,因此在 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
(base) 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=90f8960a6f1f80ae62dc18eab4bcd31fb2a6dfd7da364a6dfd7da364a\\2dpid7da364a30d7da364a\\cpipe30s\\C\\DataCache\\C\\Fulls\\C\\Fulls\\C\\F\\C\\epipe30s\\cs\\cs\\c\\s\\epipe30\\ 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)] :: Anaconda, Inc. on win32 键入“help”、“copyright” ”、“信用”或“许可证”以获取更多信息。
import readIM Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'readIM'>
导入 readIM Traceback(最近一次调用最后一次):文件“”,第 1 行,在 ModuleNotFoundError 中:没有名为“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 test Traceback(最近一次调用最后一次):文件“setup.py”,第 41 行,在 assert 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 readIM
或import readim
当它应该是import ReadIM
我不知道它区分大小写!
Thank you for your help, apologies for the trivial mistake on my part.感谢您的帮助,为我的微不足道的错误道歉。
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.检查它是否显示了您环境中 pip 的路径。 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 ...
To avoid this issue follow these steps要避免此问题,请按照以下步骤操作
conda install -c conda-forge imread
conda install -c conda-forge imread
import imread
then run.import imread
然后运行。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 readIM 或 import readim 当它应该是 import ReadIM 我不知道它区分大小写!
Thank you for your help, apologies for the trivial mistake on my part.感谢您的帮助,为我的微不足道的错误道歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.