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 variables from module 8376459 1 245 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  no module named 'docx' when importing docx MaartenRo 1 705 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  My code displays too much output when importing class from a module lil_e 4 1,101 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  pdfminer package: module isn't found Pavel_47 25 8,393 Sep-18-2022, 08:40 PM
Last Post: Larz60+
  "ModuleNotFoundError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package" chipx 3 7,236 Dec-09-2021, 07:05 AM
Last Post: chipx
Question Setuptools CLI program ModuleNotFoundError after splitting up module into package Postbote 1 2,279 Nov-25-2021, 06:35 PM
Last Post: Postbote
  Importing module in jupyter Noteboook ajitnayak1987 0 1,725 Jun-04-2021, 12:26 PM
Last Post: ajitnayak1987
  ERROR: importing desired module mbgamer28 0 1,648 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  newbie question....importing a created class ridgerunnersjw 5 2,569 Oct-01-2020, 07:59 PM
Last Post: ridgerunnersjw
  ModuleNotFoundError: No module named 'scipy.optimize'; 'scipy' is not a package AaronKR 1 10,088 Jul-09-2020, 02:36 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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