Why is "-m" needed for "python -m pip install ..."? - python-2.7

I recently used pip to install the requests package in python 2.7, however in order to do so I had to use:
python -m pip install requests
instead of just:
python pip install requests
which gave me an error:
can't open file 'pip: [Errno 2] No such file or directory
Why did I need to add the -m?

python -m pip tells python to run with the pip module as the main module.
python pip isn't understood, because pip isn't a command line argument that python understands (i.e., pip is a module).
If the python scripts directory (c:\python27\scripts for python 2.7 on windows) is on your path, then you can just run pip (without python before it) and pass the same options you would pass to python -m pip.
So: you need to add -m pip so python knows what module to use as the main module. pip is a standalone program installed in your python scripts directory, not an argument to python.

Related

Cythonizing sklearn/_isotonic.pyx failed

I'm trying to install the OCRF-Examples (https://github.com/ngoix/OCRF).
The installation instructions said:
conda create -n OCRF_env python=2.7 anaconda
source activate OCRF_env
conda install -n OCRF_env numpy scipy cython matplotlib
git clone https://github.com/ngoix/OCRF
cd OCRF
pip install --upgrade pip
pip install pyper
python setup.py install
I was able to run all the commands of the installation instructions without any problems - except for the last one:
python setup.py install
Here I got this error:
Cython is installed with the latest version (0.29.13) and no other Cython versions are installed.
If relevant: I already had Python 3.6.9 installed on my Macbook. Due to the OCRF installation, I now have Python 2.7. as additional environment.
Am I doing something wrong?

Python pip compatibility

If I use two Python versions with path variables set and later use
pip install (package name)..which pip will get activated.
Both versions come with inbuilt pip .
Iam a Python beginner..please help
Later versions of Python come with a Python Launcher. It is already in the path and allows choosing which Python to run. Remove python from your path and use the launcher instead:
py -3 -m pip <options> # Run latest Python 3 found on the system with its pip.
py -2 -m pip <options> # Use latest Python 2 instead.
The launcher has more options. See the link provided. You may need to reinstall a recent Python 3 to make sure the launcher is installed and it is registered for Python extensions.
If you are using pip then Python-2.7's pip is triggered, for Python-3.x you have to use pip3.
i.e for Python-2.7
pip install <package_name>
for Python-3.x
pip3 install <package_name>

No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

Have found a similar issue, however haven't found proper solution.
Here's a code:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,2,5])
plt.show()
Run, got the message:
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I run Linux Mint 18 with preinstalled python-2.7 and python-3.5 (I use python3), before that I was installing modules with a simple sudo apt-get install method and that worked great.
Before running this the code above, I've installed matplotlib in a usual way sudo apt-get install python-matplotlib. As it haven't worked out, started to look for solution.
Python location
which python3 /usr/bin/python3
Current Matplotlib installed
sudo find /usr | grep matplotlib /usr/lib/python3/dist-packages/matplotlib
My tries:
1) I've removed matplotlib with autoremove, and tried to make it sudo apt-get install python3-matplotlib instead. Didn't worked out.
2) Used: pip3 install matplotlib or sudo pip3 install matplotlib. Received errors like:
command python setup.py egg_info failed with error code 1 in /tmp/pip-build- ....
3) Then I found another solution:
sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install matplotlib
Same outcome.
Haven't tried to use import sys sys.path.append('/usr/lib/pymodules/python2.7/')(proposed in link above), but as I am not sure what exactly this command does (quite a newbie to python and programming itself) - haven't risked.
If you are using pycharm and have matplotlib.py in your current working directory than you get this error. Just delete or rename the matplotlib.py file and it will work.
don't name any file as matplotlib.py within your working directory
In your working directory, check if there is any file matplotlib.py
Delete that file and import matplotib again. That should work.
simply install:
python -m pip install -U pip
python -m pip install -U matplotlib
I had the same problem reasons in my case were
python 3.8.2 with matplotlib that I downloaded was for 3.7. Make sure they are the same.
python 64 bits version with matplotlib 32bits. Make sure they are the same
Use python -m pip install package_which_you_need to install packages for Windows
Make sure to add to PATH the environment variables I forgot to do in my case
pip version was old use
Use python -m pip install --upgrade pip to upgrade pip to the latest for Windows
I saved the file name as matplotlib.py. Try to avoid that
Finally I typed matplotlib.pyplot as matplotlib.plyplot remember to check for typos first. The error message looks similar even though I corrected all the steps above.
ModuleNotFoundError: No module named 'matplotlib.pyplot'
ModuleNotFoundError: No module named 'matplotlib.plyplot'

Pip installation bug

So I tried to install pip using the get-pip.py file, and when I ran the file, terminal told me I already had pip installed on 2.7. However, when I try to find the version of my pip, terminal tells me pip doesn't exist and points to a version of 3.5 I have installed. Clearly my issue is that I have pip installed on v2.7 but the pip command is linked to v3.5. Any clues on how to fix?
Here's a picture of my terminal output:
To install a package in a particular version of python, use the following commands always:
For python 2.x:
sudo python -m pip install [package]
For python 3.x:
sudo python3 -m pip install [package]
This should resolve the doubt of which python version is the given package getting installed for.
Note: This is assuming you have not created aliases for the python command

pip install pathlib

I work with python 2.7.8 and can't change the version of python because it affect other important programs. Continuously to Unzip zip files in folders and subfolders with python i don't know how to install "pip install pathlib". Any help would be great.
If on windows, type this from Command Prompt to get pathlib for Python 2.7.8:
python -m pip install pathlib2
If you're on a unix distro, type this from BASH (any shell):
pip install pathlib2
If on mac, from terminal:
sudo easy_install pip
pip install pathlib2
And now you should be able to import pathlib2 (backported version of pathlib) from Python 2.7.8.
i succeed install pathlib2 module by enter into the cmd.exe and writing:
cd C:\Users\jon\AppData\Local\Programs\Python\Python38-32\Scripts pip install pathlib2