user8483278
user8483278

Reputation:

pip install success but ModuleNotFoundError

My directory structure is:

package/
  __init__.py
  setup.py

setup.py is:

from setuptools import setup, find_packages

setup(
    name="package",
    version="0.0.1",
    packages=find_packages(),
)

When I run pip install ./package, the install successes:

Processing ./package
Installing collected packages: package
  Running setup.py install for package ... done
Successfully installed package-0.0.1

However, I can't import it:

In [1]: import package
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-f73d57b147d4> in <module>()
----> 1 import package

ModuleNotFoundError: No module named 'package'

How to create a package and import it?

Upvotes: 1

Views: 2786

Answers (1)

jmd_dk
jmd_dk

Reputation: 13120

Are you sure that the pip command really is the pip that goes along with the Python installation you are using? If you run Python using e.g.

python3 mymodule.py

you should invoke pip using

python3 -m pip install ./package

The -m pip ensures you that you get the pip that goes along with the specified Python installation.

Upvotes: 2

Related Questions