I am running a package with python -m packagename.filename.run command but it does not accept paramters like --help though if I install the package and run packagename --help it works!
How I can send parameters without need to install the package ?
Related
Clicking "Install" generates the following command:
(py310) bash-4.4$ /home/dummy/.venvs/py310/bin/python /mount/dummy/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/shell_exec.py /home/dummy/.venvs/py310/bin/python -m pip install -U ipykernel /tmp/tmp-12835ziykmDvElJGn.log
Executing command in shell >> /home/dummy/.venvs/py310/bin/python -m pip install -U ipykernel
However I need to have additional options added to running of the above command to use internally hosted repo for example:
--trusted-host artifactory.myurl --trusted-host artifactory.myurl.azurewebsites.us -i https://myurl/artifactory/api/pypi/pypi-internal/simple
Thanks
I see no options in VSCode settings to add these parameters for running of the pip install.
You can run the command manually in the terminal instead of automatically installing it by vscode.
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/
I am very new to Python programming. I can use pip install without any trouble. I've seen a lot of posts in online which prefix pip install with python -m. When I use python -m before the pip command nothing seems to happen. Please explain.
If you run python -h, the -m flag is described as:
-m mod : run library module as a script (terminates option list)
In this case, when you run python -m pip Python runs the pip module as a script (i.e. it executes the code inside it). If you have added pip to your PATH you can then just run pip directly without the need to invoke it via python.
python -m pip install <some module> and pip install <some module> should perform identically. If you have multiple versions of Python installed on your system, using pip might install a module for the wrong version of Python. You can check the version using pip -V which will output something like
pip 18.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
here the python version is python3.7.
If the version of the pip command doesn't match with the version of Python used to execute a program when the program is executed it will not run. You can check your Python version with python -V, which will output something like
Python 2.7.16
If the pip version doesn't match your Python version you can either update your path's pip, or you can use python -m pip. To select the correct version (i.e. if python runs Python 2 and you want to use Python 3) just execute python3 -m pip or python3.7 -m pip.
I am following the python-django tutorial in Vagrant (Ubuntu 18.04 / Python3.6.6). After running pip3 install pytest-django and configuring pytest.ini file, running pytest returns
Command 'pytest' not found, but can be installed with:
apt install python-pytest
Please ask your administrator.
pip3 freeze output:
pytest==3.10.0
pytest-django==3.4.3
Is there something else to the installation?
Try python -m pytest
Installing pytest via pip doesn't make it a system command, it installs it to python. The -m command runs pytest as its own command and then any proceeding script will be an argument.
I got problem when I wanted to run the following code in .sh file.
pytest-3 -s test.py
To solve it I get solution from linux itself as follows:
sudo apt install python3-pytest
On MAC OS X 10.10; I installed pytest 2.6.4; however in Terminal If I write py.test or even py.test --version; I get the error:
-bash: py.test command not found
(a) Am I missing anything? What do I do to make the pytest tool recognizable.
I searched alot; but couldn't find any info except http://teckla.idyll.org/~t/transfer/py.test.html
I checked in the PyCharm preferences, I don't see py.test interpreter listed there. However, pip freeze displays pytest 2.6.4 installed.
(b) Is PYTHONPATH required to be set on MAC? Although I've seen setting it is not required on Windows.
Appreciate any pointers to help me resolve this.
Update: Contents of my bash_profile:
echo export PATH="HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
PATH="/Users/admin/Library/Python/2.7/lib/python/site-packages:$PATH"
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH"
export PATH
On OS X you should do:
pip install -U pytest
or
easy_install -U pytest
http://pytest.org/latest/getting-started.html
Got it worked finally!
After downloading pytest, I ran the following commands and it worked like magic. I think,earlier, I missed putting "sudo" infront of the install command:
$python setup.py build
$sudo python setup.py install
The output said:
..
Installing py.test script to /usr/local/bin
Installing py.test-2.7 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pytest-2.6.4-py2.7.egg
..
Using /Users/admin/Library/Python/2.7/lib/python/site-packages
Finished processing dependencies for pytest==2.6.4
My .bash_profile contents, jfyr:
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/System/Library/Frameworks/Python.framework/Versions/2.7/bin"
export PATH
For those of us trying to avoid any and all use of sudo:
Download from PyPI here and unpack.
$ cd <pytest download folder>
$python setup.py build
$python setup.py install --user
Wherever the installing output says the "py.test script" has been installed to, add to PATH in your .bash_profile (or .bashrc if you use that for environment variables).
Confirm the setup worked via $py.test --version
pip3 install -U pytest is working with version Python 3.7
I had a problem installing pytest on Mac M1 but I followed the python pip documentation and it worked. What i did was:
istalled pip via command in Pycharm terminal (I use pycharm): python3 -m pip install pytest
after installation I run the pytest from the terminal with a command : python3 -m pytest "name_of_the_file.py"
And that works. On Mac I need to prefix all commands with "python3" cause I guess Mac has its own inbuild Python but thats Python 2 so in order to run code on my Pycharm, which was Python 3 , I need that prefix in the command... not sure though I am a newbie but something along those lines I guess