Python Forum
I cannot import the module I built for pypi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I cannot import the module I built for pypi
#1
Hello good people of the python community,

I am trying to publicize my first python package...nothing complicated, one file with one function. I have followed the usual process and after
python setup.py sdist
and
twine upload dist/*
have been completed with no errors, I can see my tarball uploaded here. The problem is, that when I fetch it with pip3, I cannot import it at all

Output:
sudo pip3 install catslog Collecting catslog Downloading catslog-1.0.5.tar.gz Building wheels for collected packages: catslog Running setup.py bdist_wheel for catslog ... done Stored in directory: /root/.cache/pip/wheels/f5/8e/c0/f26ca927ba894c8722ac0d832f4dc0c1ea765de703fb5a7827 Successfully built catslog Installing collected packages: catslog Successfully installed catslog-1.0.5 periklis@tigerpc:~$ python Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import catslog Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'catslog'
Am I missing something? Could you please shed some light? I couldnt find an FAQ, so I would be grateful if you have something handy.
Reply
#2
You have build it as a package.
Then is your folder named src also part of import.
(my_env) E:\1\my_env
λ pip install catslog
Collecting catslog
  Downloading catslog-1.0.5.tar.gz
Installing collected packages: catslog
  Running setup.py install for catslog ... done
Successfully installed catslog-1.0.5

>>> import src
>>> src.catslog
<module 'src.catslog' from 'E:\\1\\my_env\\lib\\site-packages\\src\\catslog.py'>
>>> help(src.catslog)
Help on module src.catslog in src:

NAME
    src.catslog

FUNCTIONS
    catslog(f)

FILE
    e:\1\my_env\lib\site-packages\src\catslog.py
If it's a singe module can use py_modules=['catslog'] in setup.py,and just drop package.
Eg
# setup.py
from setuptools import setup
 
__author__ = 'you'
 
setup(
   name="catslog",
   version='0.1',
   py_modules=['catslog'],
   description="Something",
   url='',
   author_email='something@',
)
You should always build wheel and not source distributions(sdist).
python setup.py bdist_wheel
Reply
#3
Wow, so simple and genius that I feel ashamed. Big Grin
Many thanks snippsat. Clap
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 385 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,261 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 683 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 3,380 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,038 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Import a module for use in type hint? Milosz 0 1,455 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,743 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 5,163 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'urllib3' Module not found when import 'requests' spanz 5 9,963 Jan-06-2021, 05:57 PM
Last Post: snippsat
  Problem with Flask Bcrypt import module marcello86 2 5,598 Aug-31-2020, 08:10 PM
Last Post: marcello86

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020