0

I try to reorganize parts of my code into packages to be delivered by pip. But I do not understand the following: There is a directory my_package containing _init.py (empty), my_module.py (with some code), setup.py:

from setuptools import setup, find_packages

setup(
    name='mypackage',
    version='0.1',
    description='My Package',
    author='Its me',
    author_email='my.email@address.moon',
    packages=find_packages(),
    install_requires=[
        'cx_Oracle>=7.2.2'
    ]
)

I created a dist- file dist\mypackage-0.1.tar.gz by

...my_package>python.exe setup.py sdist

I created a virtual environment, activated it, used

...inside_venv>Scripts\pip.exe install <complete_path_to_dist\mypackage-0.1.tar.gz>

created a test-file test.py

import cx_Oracle
print(cx_Oracle.version)
import mypackage

everything worked (I got the message "newer PIP- Version available...")

cx_Oracle is installed w/o any problems (the version is newer than all others), but it is impossible to import my packages ModuleNotFoundError: No module named 'mypackage'

I tried the following:

  • Originally the packages was called my_package and I spent many time to try combinations with _ and -, so that I decided to name the package without "_"
  • I updated pip in the venv
  • I installed the package outside of venv

Whatever I tried, the answer was: ModuleNotFoundError: No module named 'mypackage'

(BTW: The code inside my_module.py works without problems, if I use it directly)

Any Ideas?

am2
  • 11
  • 3
  • 1
    What if you `import my_package`? It seems that you have declared the installable package name to be `mypackage` but the importable thing is the directory called `my_package`. The two are independent, which causes much confusion, see https://stackoverflow.com/q/11453866/3324095. – FiddleStix Jul 12 '23 at 08:55
  • as I explained before: I tried my_package too, it didn't work. pip showed the package as my-package (similar to the Oracle- package) and so I tried import my_package - same answer – am2 Jul 12 '23 at 09:00

0 Answers0