[英]Module not found after installing .whl package locally
I installed a.whl package locally using pip:我使用 pip 在本地安装了 a.whl package:
pip install package_name.whl
Now, when running现在,运行时
pip list
The package appears with the relative version installed. package 出现时安装了相关版本。
I checked if pip is linked to the right version of python, i used:我检查了 pip 是否链接到 python 的正确版本,我使用了:
pip -V
And this is the answer:这就是答案:
pip 21.3.1 from /home/username/.local/lib/python3.8/site-packages/pip (python 3.8)
When running python on the shell:在 shell 上运行 python 时:
python3.8
And i try to import the package this is the answer:我尝试导入 package 这就是答案:
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import package_name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'package_name'
Also in python3.8 when i run:当我运行时也在python3.8中:
help("modules")
The package_name module in fact does not appear. package_name 模块实际上并没有出现。 So?
所以? what is happening?
怎么了?
I have also 3.5 and 2.7 python version, and to be sure if it is installed in other versions i made the same thing in the shell and no one could import the package or locate it.我还有 3.5 和 2.7 python 版本,为了确定它是否安装在其他版本中,我在 shell 中做了同样的事情,没有人可以导入 ZEFE90A8E604A7C840E88D03A67F6 或找到它。 Also i tried to install the.whl file with:
我还尝试使用以下命令安装 .whl 文件:
python3.8 -m pip install package_name.whl
Then in the output of然后在output的
python3.8 -m pip list
the package_name is there. package_name 在那里。 But again could not import into the shell of python3.8 or even locate it when running again
但是再次运行时无法导入python3.8的shell甚至无法定位
help("modules")
Solved:解决了:
When i try to uninstall the package with pip this massage appears:当我尝试使用 pip 卸载 package 时,出现此消息:
Found existing installation: package_name 0.0.7
Uninstalling package_name-0.0.7:
Would remove:
/home/username/.local/lib/python3.8/site-packages/package_name-0.0.7.dist-info/*
/home/username/.local/lib/python3.8/site-packages/package_name_2.cpython-38-x86_64-linux-gnu.so
Proceed (Y/n)? y
Successfully uninstalled package_name-0.0.7
The package has been built with cython and as you can see it depends on a.so library with 'package_name_2' different name respect to 'package_name'. package 是用 cython 构建的,如您所见,它依赖于具有“package_name_2”的 a.so 库,其名称与“package_name”不同。
When i run当我跑步时
help("modules")
in python3.8 package_name_2 actually appears.在python3.8 package_name_2 中实际出现。 And the library works if i import package_name_2.
如果我导入 package_name_2,该库就可以工作。 When building a.whl package with cython there should be some name dependencies constrained to the.so library to which the cython modules are referenced i think, so, for other developers, a suggestion: if you build a.whl using cython, if you are using a shared library be sure that the lib.so that you compile has the same name of the supposed python package.
在使用 cython 构建 a.whl package 时,我认为应该有一些名称依赖项受限于 .so 库,而我认为 cython 模块引用到这些库,因此,对于其他开发人员,一个建议是:如果您使用 cython 构建 a.whl,如果您正在使用共享库确保您编译的 lib.so 与假定的 python package 具有相同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.