[英]Python: Unable to install as a module but a package
As I need to run python with specifying a module, but not to run the install package as the executable, I tried to install the package locally, but it does not install as a module but as a package for some reason. As I need to run python with specifying a module, but not to run the install package as the executable, I tried to install the package locally, but it does not install as a module but as a package for some reason.
Here is the series of commands what I did.这是我所做的一系列命令。
# enable virtualenv
# now, no external pip package is installed
$ . ./venv02/bin/activate
# install the module
$ pip install mitmproxy
# I thought this should be worked, but it does not.
$ python -m mitmproxy --mode upstream:https://localhost:3148 --listen-port 8085 --scripts ./mitmproxy_main.py
/home/user/pg/python/venv02/bin/python: No module named mitmproxy.__main__; 'mitmproxy' is a package and cannot be directly executed
# but as a package I can run
# but this is not what I desire,
# since in the later step I need to use the "module" mitmproxy in vscode launch.json to debug the python script ./mitmproxy_main.py.
$ mitmproxy --mode upstream:https://localhost:3148 --listen-port 8085 --scripts ./mitmproxy_main.py
The virtualenv Python version and pip version is as follows. virtualenv Python 版本和 pip 版本如下。
(venv02) user@pc:~/pg/python$ python --version
Python 3.6.12
(venv02) user@pc:~/pg/python$ pip --version
pip 21.2.4 from /home/user/pg/python/venv02/lib/python3.6/site-packages/pip (python 3.6)
So How can I install a "module" locally to run python -m [module]
?那么如何在本地安装“模块”来运行python -m [module]
? Thanks.谢谢。
As much as I know, to install python packages locally:据我所知,要在本地安装 python 包:
for python 3: pip3 install --user <package>
Also try doing:也尝试做:
pip3 install <your_python_module_name> -t lib/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.