Python Forum

Full Version: Help with importing a module from a package I created.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
(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
(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.