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.
(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]
? Thanks.
As much as I know, to install python packages locally:
for python 3: pip3 install --user <package>
Also try doing:
pip3 install <your_python_module_name> -t lib/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.