简体   繁体   中英

Module not found after installing .whl package locally

I installed a.whl package locally using pip:

pip install package_name.whl

Now, when running

pip list

The package appears with the relative version installed.

I checked if pip is linked to the right version of python, i used:

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:

python3.8

And i try to import the package this is the answer:

[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:

help("modules")

The package_name module in fact does not appear. 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. Also i tried to install the.whl file with:

python3.8 -m pip install package_name.whl

Then in the output of

python3.8 -m pip list

the package_name is there. But again could not import into the shell of python3.8 or even locate it when running again

help("modules")

Solved:

When i try to uninstall the package with pip this massage appears:

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'.

When i run

help("modules")

in python3.8 package_name_2 actually appears. And the library works if i import 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM