Python Forum
Help with importing a module from a package I created.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with importing a module from a package I created.
#1
Hi, I published a package in PyPI and I'm able to import it. The thing is that to use the functions that the package includes which are two functions, one called encrypt_text and another one called decrypt_text, I need to import them like this:

from w_encryption.encrypt_text import *

print(encrypt_text('Hello'))
My question is: How do I change this so I'm able to import them like:
from w_encryption import encrypt_text
or importing like this:
import w_encryption
If I import the module in those two ways I get this error:
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'module' object is not callable
Do I have to edit the __init__.py file? Now I have it like this:
name = "w_encryption"

from w_encryption import encrypt_text
from w_encryption import decrypt_text
Or do I have to edit the setup.py file outside the folder where the functions files are and where __init__.py is?
setup.py:
import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="w_encryption",
    version="1.0.1",
    author="Francisco Wendeburg",
    author_email="[email protected]",
    description="w_ncryption is a Python library that can encrypt and decrypt text.",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/fwendeburg/w_encryption",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Topic :: Utilities",
        "Topic :: Security :: Cryptography",
    ],
)
Thanks in advance for your response.
Reply
#2
(Mar-12-2019, 01:57 AM)FWendeburg Wrote: My question is: How do I change this so I'm able to import them like:
from w_encryption import encrypt_text
Yes this is the way it should be done,never make a package that use *.

Quote:Do I have to edit the __init__.py file? Now I have it like this:
Look a this post,see how i lift the sub modules.
look at the . that's needed for doing this.
snippsat Wrote:.color import base_color
Reply
#3
(Mar-12-2019, 08:43 AM)snippsat Wrote:
(Mar-12-2019, 01:57 AM)FWendeburg Wrote: My question is: How do I change this so I'm able to import them like:
from w_encryption import encrypt_text
Yes this is the way it should be done,never make a package that use *.

Quote:Do I have to edit the __init__.py file? Now I have it like this:
Look a this post,see how i lift the sub modules.
look at the . that's needed for doing this.
snippsat Wrote:.color import base_color

Thanks! It works now xd.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Importing module in jupyter Noteboook ajitnayak1987 0 307 Jun-04-2021, 12:26 PM
Last Post: ajitnayak1987
  ERROR: importing desired module mbgamer28 0 342 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  newbie question....importing a created class ridgerunnersjw 5 722 Oct-01-2020, 07:59 PM
Last Post: ridgerunnersjw
  ModuleNotFoundError: No module named 'scipy.optimize'; 'scipy' is not a package AaronKR 1 3,300 Jul-09-2020, 02:36 AM
Last Post: bowlofred
  ModuleNotFoundError: No module named 'http.client'; 'http' is not a package abhishek81py 1 3,940 Jun-25-2020, 08:58 AM
Last Post: buran
  importing module - not working jdhamblett 3 849 Jun-22-2020, 07:33 PM
Last Post: jdhamblett
  importing same python library in multiple custom module escape_freedom13 6 1,305 May-10-2020, 07:01 PM
Last Post: escape_freedom13
  Importing module from a package results in import error goghvv 2 798 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Error importing package julio2000 3 1,309 Jan-26-2020, 06:15 PM
Last Post: buran
  Please help: problem installing/importing langdetect module in Jupyter Notebook ledgreve 3 3,163 Dec-30-2019, 08:17 AM
Last Post: LeanbridgeTech

Forum Jump:

User Panel Messages

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