I'm trying to create a python package for the first time, using setuptools.
Let's imagine my package is named qwerty.
Here's my project structure:
qwerty (folder)
++ src (folder)
--++ __init__.py
--++ control.py
--++ modes.py
--++ data.dic
--++ utils.py
--++ version.py
--++ qwerty.py
++ __init__.py
++ __main__.py
CHANGELOG.md
commands.txt
README.md
image.gif
setup.py
My setup.py contains the following code:
import setuptools as st
import os
exec(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "qwerty/src/version.py")).read())
st.setup(
include_package_data=True,
version=__version__,
(...)
package_data={"": ["*.dic"]},
packages=st.find_packages(where="qwerty"),
package_dir={"": "qwerty"},
entry_points={"console_scripts": ["qwerty=qwerty.__main__:main"]}
)
And my __main__.py contains the following code:
from .src.qwerty import main
if __name__ == "__main__":
main()
I'm using the following command to create/install the package:
$ pip install .
When I install the program, it is installed in /usr/local/bin. My goal here is that the final binary executes the main function located in qwerty/src/qwerty.py. But I must be doing something wrong because after installing the package, when I run the program, I get the following output:
Traceback (most recent call last):
File "/usr/local/bin/qwerty", line 33, in <module>
sys.exit(load_entry_point('qwerty==1.0.3', 'console_scripts', 'qwerty')())
File "/usr/local/bin/qwerty", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'qwerty'
I already tried using entry_points={"console_scripts": ["qwerty=qwerty.src.qwerty:main"]} as the entry point in setup.py, but got the exact same output.
Can someone try to explain me what I'm doing wrong and how I can fix this problem?
Thank you in advance.
Related
I am using rasa as a python library. Here is my directory structure
chat-bot/
bots/
models/
rasa/
my-model.tar.gz
rasa_bot.py
projects/
rasa/
actions/
components/
data_processing.py
data/
nlu.yml
stories.yml
config.yml
domain.yml
Here is how my config.yml
language: en
pipeline:
- name: components.data_processing.DataProcessingComponent
- name: WhitespaceTokenizer
- name: CountVectorsFeaturizer
and this is how I train the model
rasa train --fixed-model-name my-model --out ../../bots/models/rasa/
And in rasa_bot.py This is how I am loading the model
model = RasaBot.__get_model("my-model.tar.gz")
# get the agent from model and action server
ACTION_ENDPOINT = os.getenv('ACTION_ENDPOINT')
agent = Agent.load(
model,
action_endpoint=EndpointConfig(ACTION_ENDPOINT)
)
and __get_model method
#staticmethod
def __get_model(modelName):
MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
return '{}/{}'.format(MODEL_LOCATION, modelName)
but this is showing this error
Failed to load the component 'components.data_processing.DataProcessingComponent'. Failed to find module 'components.data_processing'. Either your pipeline configuration contains an error or the module you are trying to import is broken (e.g. the module is trying to import a package that is not installed). Traceback (most recent call last):
File "c:\chat-bot\env37\lib\site-packages\rasa\nlu\registry.py", line 121, in get_component_class
return rasa.shared.utils.common.class_from_module_path(component_name)
File "c:\chat-bot\env37\lib\site-packages\rasa\shared\utils\common.py", line 37, in class_from_module_path
m = importlib.import_module(module_name)
File "C:\Users\sgarg\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'components'
Could you add an empty __init__.py file to your components folder? That way the folder is detected as a Python module.
Note that I'm assuming that you're running the rasa train command from the projects/rasa folder here.
In my rasa_bot.py, I added
RASA_DIR = os.getcwd() + "//projects//rasa"
sys.path.append(RASA_DIR)
and it worked
I’m running into an issue getting pyInstaller to bundle a module that contains SWIG modules. I have followed each of the guidelines listed in the pyInstaller doc which details SWIG support.
I get the following error when running the exe:
# sphinxbase._ad_win32 not found in PYZ
Traceback (most recent call last):
File "StartListening.py", line 10, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\allen\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sphinxbase\__init__.py", line 35, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\allen\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sphinxbase\ad_win32.py", line 32, in <module>
File "site-packages\sphinxbase\ad_win32.py", line 31, in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sphinxbase._ad_win32'
However, sphinxbase._ad_win32 does exists as a pyd file. I’m running Windows 10; why is pyInstaller having trouble bundling this module?
The third-party package I’m ultimately trying to import is SpeechRecognition which depends on pocketsphinx which depends on sphinxbase which is the module that is having issues.
Here is the object reference returned by
importlib.import_module('sphinxbase._ad_win32')
in the SWIG-generated python wrapper if that is helpful to someone:
<module 'sphinxbase._ad_win32' from 'C:\\Users\\bob\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\sphinxbase\\_ad_win32.pyd'>
Python version: 3.6.5
Edit: After some more research, I tried adding the .pyd to the 'binaries' list in the .spec file as well as adding 'sphinxbase._ad_win32' to the 'hidden-imports' list and combinations there-between, but this did not work either. The binary is there, in the correct location, I can't figure out why the bundled app can't find it.
I installed azure-cli with Homebrew brew update && brew install azure-cli
None of the azure commands have been successful. No matter the command I get the the following error.
az storage container create --name testContainer
No module named 'pkg_resources'
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/knack/cli.py", line 197, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 262, in execute
self.commands_loader.load_arguments(command)
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/azure/cli/core/__init__.py", line 253, in load_arguments
self.command_table[command].load_arguments() # this loads the arguments via reflection
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 141, in load_arguments
super(AzCliCommand, self).load_arguments()
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/knack/commands.py", line 76, in load_arguments
cmd_args = self.arguments_loader()
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/azure/cli/core/__init__.py", line 440, in default_arguments_loader
op = handler or self.get_op_handler(operation)
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/azure/cli/core/__init__.py", line 485, in get_op_handler
op = import_module(mod_to_import)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/Cellar/azure-cli/2.0.45/libexec/lib/python3.7/site-packages/azure/multiapi/__init__.py", line 1, in <module>
__import__('pkg_resources').declare_namespace(__name__)
ModuleNotFoundError: No module named 'pkg_resources'
I've attempted to do pip install setuptools
which gives me:
Requirement already satisfied: setuptools in ./Library/Python/2.7/lib/python/site-packages (40.4.1)
Is azure trying to use a different version of python that's missing setup tools? Am I using the wrong version of python?
I don't really know where to go from here.
python --version says i'm using Python 3.7.0
As you say none of the azure commands have been successful. So I suggest you reinstall the Azure CLI, you can follow Install Azure CLI 2.0.
Additional, install Azure CLI through python:
pip install --pre --user azure-nspkg
pip install --pre --user azure-multiapi-storage
pip install azure-cli
For more details, follow this link.
About create a container for the storage. You can do that with the CLI command here:
az storage container create --name containerName --account-name accountName --account-key accountKey
And the container name has the limitation here:
A container organizes a set of blobs, similar to a folder in a file
system. All blobs reside within a container. A storage account can
contain an unlimited number of containers, and a container can store
an unlimited number of blobs. Note that the container name must be
lowercase.
So you should pay attention to it. Hope this will help you.
(venv) E:\Studia Materialy\Semestr 4\IO\l02-nr-6-cyber-mechanik-l02team- master>python manage.py makemigrations L02
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\keray\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\keray\venv\lib\site-packages\django\core\management\__init__.py", line 357, in execute django.setup()
File "C:\Users\keray\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\keray\venv\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\keray\venv\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "E:\Programowanie\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'snowpenguin'
Can't run python manage.py runserver because of this problem, python 3.7, Django 2.0.7. I have tried many versions of python, and Django, I have also reinstalled bootstrap.
For me, I had to download django-recaptcha versions 2 & 3. Might be different for you though. Just follow #Lemayzeur's comment and look in your INSTALLED_APPS to find out what to download via pip.
Background: I'm taking a beginners Django course and I've run into an issue. The following command isn't working in Terminal.
Running on Mac
Virtual environment
Taking UDEMY Course: try-django-v1-11-python-web-development
Command: python manage.py migrate
Terminal Output:
(trydjango1-11) C02T74CKGTF1:src josh.frazier$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/josh.frazier/Dev/trydjango1-11/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/josh.frazier/Dev/trydjango1-11/lib/python3.6/site-packages/django/core/management/__init__.py", line 307, in execute
settings.INSTALLED_APPS
File "/Users/josh.frazier/Dev/trydjango1-11/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/josh.frazier/Dev/trydjango1-11/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/josh.frazier/Dev/trydjango1-11/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Users/josh.frazier/Dev/trydjango1-11/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/josh.frazier/Dev/trydjango1-11/src/muypicky/__init__.py", line 1, in <module>
from .base import *
ModuleNotFoundError: No module named 'muypicky.base'
After going through your files, i found that you haven't imported local.py and production.py in your __init__.py add the following code to __init__.py file inside settings folder
from .base import *
from .production import *
try:
from .local import *
except:
pass