multipledispatch ModuleNotFoundError running from command-line

一世执手 提交于 2021-02-08 06:40:14

问题


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:

  1. Add directories to the PYTHONPATH environment variable
  2. Add empty __init__.py files in each package

This all seems unnecessary if I actually pip installed 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:

  1. cd your_working_directory
  2. environment_name/Scripts/activate if on Windows where environment_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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!