-2

I uploaded my first PyPi package today. It took me a while to figure everything out, but I did it, and now I'm trying to import it to another project of mine.

Unfortunately I get a ModuleNotFoundError. I'm on Windows 10, running python 3.9.6. I've tried everything I've seen on the internet, deleted the venv and recreated it, reuploaded the package to PyPi, installed it with python -m pip install sqlcontroller and even with ./venv/Scripts/python.exe -m pip install sqlcontroller. I'll try to supply all the info I can below.

The PyPi package: https://pypi.org/project/sqlcontroller/

On Github: https://github.com/RedKnight91/sqlcontroller

(venv) PS C:\Users\mikec\Documents\Python\binance-trading-bot-evaluator> python -m pip install sqlcontroller --no-cache-dir --upgrade 
Requirement already satisfied: sqlcontroller in c:\users\mikec\documents\python\binance-trading-bot-evaluator\venv\lib\site-packages (0.0.2)

import sqlcontroller results in:

Traceback (most recent call last):
  File "c:\Users\mikec\Documents\Python\binance-trading-bot-evaluator\src\main.py", line 2, in <module>
    from sqlcontroller import SqlController
ModuleNotFoundError: No module named 'sqlcontroller'

pip show output

(venv) PS C:\Users\mikec\Documents\Python\binance-trading-bot-evaluator> python -m pip show sqlcontroller --files
Name: sqlcontroller
Version: 0.0.2
Summary: Controller class to handle sqlite3 databases.
Home-page: https://github.com/RedKnight91/sqlcontroller
Author: Michael Cazzarolli
Author-email: mikecazzarolli@gmail.com
License: UNKNOWN
Location: c:\users\mikec\documents\python\binance-trading-bot-evaluator\venv\lib\site-packages
Requires:
Required-by:
Files:
  sqlcontroller-0.0.2.dist-info\INSTALLER
  sqlcontroller-0.0.2.dist-info\LICENSE
  sqlcontroller-0.0.2.dist-info\METADATA
  sqlcontroller-0.0.2.dist-info\RECORD
  sqlcontroller-0.0.2.dist-info\REQUESTED
  sqlcontroller-0.0.2.dist-info\WHEEL
  sqlcontroller-0.0.2.dist-info\top_level.txt
  src\__init__.py
  src\__pycache__\__init__.cpython-39.pyc
  src\__pycache__\sqlcontroller.cpython-39.pyc
  src\sqlcontroller.py
  tests\__init__.py
  tests\__pycache__\__init__.cpython-39.pyc
  tests\__pycache__\conftest.cpython-39.pyc
  tests\__pycache__\test_sqlcontroller.cpython-39.pyc
  tests\conftest.py
  tests\test_sqlcontroller.py

where python gives no output from venv:

(venv) PS C:\Users\mikec\Documents\Python\binance-trading-bot-evaluator> where python
(venv) PS C:\Users\mikec\Documents\Python\binance-trading-bot-evaluator> 

but it does from outside:

C:\Users\mikec>where python
C:\Users\mikec\AppData\Local\Programs\Python\Python39\python.exe

pip freeze

(venv) PS C:\Users\mikec\Documents\Python\binance-trading-bot-evaluator> pip freeze
sqlcontroller==0.0.2
RedKnight91
  • 340
  • 3
  • 17
  • Please edit the question to show your setup.py / setup.cfg and/or pyproject.toml. They are not present in the github repo. – wim Sep 02 '21 at 19:08
  • This youtube video is your friend: https://www.youtube.com/watch?v=4fzAMdLKC5k&list=WL&index=4 – Austin Sep 02 '21 at 19:09

2 Answers2

1

Your package is called "src", so the installed module should be importable currently with

from src import sqlcontroller

or

import src.sqlcontroller as sqlcontroller

However, this is poorly packaged. You should name the top-level package as sqlcontroller, not src, and you should not package the tests subdirectory at all.

wim
  • 338,267
  • 99
  • 616
  • 750
  • Thanks! I fixed the package name (changed to sqlcontroller), how can I only package that? This is my setup.cfg `[options] packages = find: python_requires = >=3.6` I've tried using 'package_dir' but without success – RedKnight91 Sep 02 '21 at 20:02
  • @RedKnight91 You need to specify the "where" if you're going to use the src layout. It's shown how to do it here: https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html#using-a-src-layout – wim Sep 02 '21 at 23:01
  • I tried that replacing the two 'src' with 'sqlcontroller' but it includes no modules that way – RedKnight91 Sep 03 '21 at 06:24
1

You have a wrong file structure

This is an example how my package looks

(venv) PS D:\Python\thebot> pip show bdbf --files
Name: bdbf
Author: Bertik23
Author-email: bertikxxiii@gmail.com
License: UNKNOWN
Location: d:\python\thebot\venv\lib\site-packages
Requires: discord.py
Required-by:
Files:
  bdbf-1.1.2.dist-info\INSTALLER
  bdbf-1.1.2.dist-info\LICENSE
  bdbf-1.1.2.dist-info\METADATA
  bdbf-1.1.2.dist-info\top_level.txt
  bdbf\__init__.py
  bdbf\__pycache__\__init__.cpython-39.pyc
  bdbf\__pycache__\bdbf.cpython-39.pyc
  bdbf\__pycache__\exceptions.cpython-39.pyc
  bdbf\__pycache__\functions.cpython-39.pyc
  bdbf\__pycache__\main.cpython-39.pyc
  bdbf\bdbf.py
  bdbf\exceptions.py
  bdbf\functions.py
  bdbf\main.py

As you can see, all of the .py filles are in the bdbf folder, but yours are in src, that is than the name you have to import, so if you do import src you probably would import your package

Bertik23
  • 401
  • 4
  • 9