问题
Running a locust
(locust.io) script from the command line.
locust
calls main.py
which has the following imports:
from locust import HttpUser, between, task
from StreamLoader.stream_generator import * # thought this brings in everything
Packer.py
has these imports:
from multipledispatch import dispatch
from PackedItem import PackedItem
StreamGenerator.py
has:
import hashlib
from StreamLoader.Packer import Packer
from aes_encryption import AesEncryption
I used pip
to install multipledispatch
and when I run from within PyCharm it works fine, but from the command line I get the following.
File "C:\Users\guyl\PycharmProjects\engine-load-tests\engine_load_tester_locust\main.py", line 2, in <module>
from StreamLoader.stream_generator import *
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\stream_generator.py", line 2, in <module>
from StreamLoader.Packer import Packer
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\Packer.py", line 1, in <module>
from multipledispatch import dispatch
ModuleNotFoundError: No module named 'multipledispatch'
Here is what I have tried so far:
- Add directories to the PYTHONPATH environment variable
- Add empty
__init__.py
files in each package
This all seems unnecessary if I actually pip install
ed the module, though.
Answer below caused me to no longer see the error with multipledispatch
. However, I now see a missing module error:
File "C:\Users\guyl\PycharmProjects\engine-load-tests\engine_load_tester_locust\main.py", line 2, in <module>
from StreamLoader.stream_generator import *
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\stream_generator.py", line 2, in <module>
from Packer import Packer
ModuleNotFoundError: No module named 'Packer'
For clarity, I am running the code from locust
which calls the Python code as depicted here. [Moderators - this question is getting quite long. Is that all right?]
回答1:
PyCharm uses the virtual environment automatically but when you run from the command line the virtual environment isn't turned on.
Just follow the steps:
cd your_working_directory
environment_name/Scripts/activate
if onWindows
whereenvironment_name
is the name of the PyCharm virtual environment
Or environment_name/bin/activate
if on MacOS
-------------EDIT------------------------
To answer the new question, try using pip freeze
then see which packages are installed. Then install any dependencies which you want which are missing.
来源:https://stackoverflow.com/questions/65523535/multipledispatch-modulenotfounderror-running-from-command-line