How to make pip available to git bash command line on Windows? - python

I added the pip installation folder in my python site-packages directory to my PATH, but I can still only run it via python -m pip in my git bash. Just pip gives me command not found.
I looked around the pip directory and I don't see any binaries, so this makes sense. Yet clearly pip is a thing that is normally used on the command line without python -m. So what component am I missing here?

Try adding C:/path/to/python/Scripts/ to PATH
There should be a pip.exe there!

in your Anaconda directory there is a pip file in the direcctory Scripts.
add this path : C:\Users#yourname\Anaconda3\Scripts
i did the same and it was successful !!
(when i wrote pip in git bash it worked)

Related

pip is installed in pycharm but cant able to run pip commands

Inside my pycharm package section pip (v:21.3.1) is showing as installed but when running pip commands it shows following error
pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
use !pip that might help. Else, try to see pip list and uninstall the package and try uninstalling using '!pip', this takes directly outside the main terminal.
My guess is that you are not inside the Pycharm virtual environment.
Try to go to the terminal/command line and go to the project directory,
you should look for 'venv' directory.
Than activate the virtual enviorment.
terminal:
source /venv/Scripts/activate (run activate.sh file)
command line
call /venv/Scripts/activate (run activate.bat file)
and then you will be able to run pip
Solution 1:
Install packages within pycharm & run the code within pycharm
Solution 2:
Find python.exe in the install directonary, open cmd in the folder and run following:
python.exe -m pip install ...
Solution 3:
activate the venv (you can find instructions on google or use the one from the dude above)
This might help
python -m pip install <package name>
Different solutions to this problem:
First: you are not on the pycharm terminal but on the power-shell terminal
(if so, use the drop-down menu to the right of the +)
edit: if you opened the file/folder without creating a project, pip won't work in it (using a virtual env anyway)
Second : you have a python3 environment
(use pip3 instead)
Last : your path is badly configured (not a big problem, passing by python -m pip ... it will work (or python3 or other version installed))
Finally, except in very specific cases
file->setting->python Interpreter allows you to install anything you want without command line
Hoping to have helped you ;}

How do I run this python script?

I'm new to python, and I was wondering if you could help me run a python script. I'm trying to run a script called PunchBox from Github: https://github.com/psav/punchbox. So far, I have Python 3.9.5 and Git Bash.
In the GitHub page, it says:
To install, clone the repo, cd into it and then execute the following:
virtualenv -p python2 .pb2
source .pb2/bin/activate
pip install -U pip
pip install .
What does this mean exactly? Where do I run this code?
So far, I tried downloading the zip file from GitHub, installing Python 3.5.9, using cmd, finding the directory with cd, and running that code; but got an error:
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name punchbox was given, but was not able to be found.
error in punchbox setup command: Error parsing C:\Users\Mi\Downloads\punchbox-master\punchbox-master\setup.cfg: Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name punchbox was given, but was not able to be found.
There's also a requirements.txt that lists additional scripts needed:
pre-commit
click
mido
pbr
PyYAML
svgwrite
Do these install automatically upon running the script for the first time?
I'm a little confused why I'm getting an error. Do you know what I'm doing wrong?
Thank you so much!
Giovanni
I assume you are new to programming. You have to write these lines in a terminal.
On Windows, it is Command Prompt or PowerShell Applications (latter preferred). On macOS, it is terminal
Copy all these lines at once, and paste them to your preferred terminal. The terminal will automatically run these one after the another.
FYI: Venv is a python package to create a virtual environment. The preceding commands set up the environment. Now install the required dependencies using this command instead of the last command (pip install .)
pip install -r requirements.txt
Based on your comment, it looks like you don't have virtualenv installed in your system. You may install it using the command pip install virtualenv.
Now, as you are using a Windows machine, you may open a Command Prompt or Windows PowerShell window and navigate to the directory where your cloned project resides.
Now, execute the following commands.
virtualenv -p python2 .pb2
.pb2\Scripts\activate.bat
pip install -U pip
pip install -r requirements.txt
Once you are done working in your virtual environment (which is named .pb2), you may close it by executing deactivate command.
#Giovanni T.
See, as far as you have installed Python and also downloaded the GitHub Repository as a zip file.
pip install -r requirements.txt
Just run this command.
Please make sure that the directory is pointing to the folder where this requirements.txt file is stored.

why "pip install" doesn't work but "python -m pip install" works?

I've recently reinstalled windows on my workstation so I needed to reinstall python and pip, before the reinstallation, the command pip install whatever was working properly.
But then after the reinstallation of Windows 10 when I type that command it won't return anything, not even an error, I've searched other solution and I found that this command python -m pip install whatever works fine.
What is changed?
How can I let the first command work again?
This is a PATH problem. On a standard Python3 installation on Windows, python.exe and pip.exe are in different folders. Let us say that Python is installed just under TOP, then:
python.exe (and pythonw.exe) are in TOP\Python3x (x being minor version such as Python37)
pip.exe is in TOP\Python3x\Scripts
py.exe is in WINDOWSDIR (normally C:\Windows)
That is the reason why:
py -m pip install ... always works on Windows (provided pip is installed)
python -m pip install ... requires ...\Python3x to be in the PATH
pip install ... requires ...\Python3x\Scripts to be in the PATH
As Bensalem has said, you need to add pip to your variable path in order to be able to use it without calling the script with python (which is in your path).
The -m refers to the passable argument to python;
-m mod : run library module as a script (terminates option list)
pip is a python script, and because you have not added to path variable the link to the "Scripts" folder;
this "Scripts" folder is situated on "C:location where python is installed\Scripts";
ex. for me : "C:\Python36\Scripts"; so i type on cmd prompt to set the path variable:
set PATH=%PATH%;C:\Python36\Scripts
you can see the link: [https://www.computerhope.com/issues/ch000549.htm]
you should add pip to ur environment variable(path windows), try this

My PYTHONPATH env doesn't seem to work

I've installed pip on my computer(mac), and I tried these:
$export PYTHONPATH=/usr/local/lib/python2.7/site-packages/pip
$python pip freeze list
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'pip': [Errno 2] No such file or directory
It doesn't work, but if I specify this full path into python command, it works:
$python /usr/local/lib/python2.7/site-packages/pip freeze list
ant==0.1.0
appnope==0.1.0
astroid==1.4.8
backports-abc==0.5
........
Why is that?
Running pip freeze directly should be sufficient. You shouldn't have to run it via python pip or tweak $PYTHONPATH at all.
The error in that first snippet has to do with how you are invoking python. Your command is interpreted as python <script-filename> [script-arguments ...]. The filename you are passing in is pip, so python looks for a file named "pip" in the current directory. That file does not exist, so python crashes with a "file not found" error.
python <full-path-to-script> works because... well, why wouldn't it? Python finds the script and executes it.
As pointed out in the comments you don't want to mess around with PYTHONPATH. If you want to have different versions of python on the same computer or python installations with different installed packages (or modules) what you need is to use virtualenv
Create a new virtualenv.
virtualenv /usr/local/custom-python/
and then whenever you want to use it or install packages into it, just do
source /usr/local/custom-python/bin/activate
try to use:
$export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
Firstly, your code may cover the orignal PYTHONPATH which is deprecated. Secondly, do not include pip into the python path because pip is a package that should be included.
python /your/path/to/pip this pip is a folder in which there is a __init__.py . So python can read it. But if you directly define PYTHONPATH to pip folder, python will not find this __init__.py to represent pip (See document about python import packge)
Besides, I think you can include the binary pip (may located /usr/bin) in into your path so that you can call it directly with $ pip command

pip: command not found

I encounter a problem when installing pip for python2.7. I downloaded the file get-pip.py, and install it successfully:
bogon:haha itensb$ python get-pip.py
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages
Cleaning up...
But when I run the command pip, I got:
-bash: pip: command not found
I think it is the PATH not set appropriatelly , But I new on Mac. I need your help , thanks!
Use python -m pip. If you want the pip command check out #user3282276's answer.
Sounds like your PATH variable is not set to include the location that pip was installed to. On Macs and other *nix like operating systems when you type a command in the command line, what is actually happening is the shell is trying to find the executable file in a predefined area, called the PATH variable. If you are interested check out this question, https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them.
You are able to see what yours is set to if you do this in your command line
echo $PATH
this will give you some file paths separated by colons, for example when I type the command above I get this:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Applications/Android Dev Tool/sdk/tools
which means that my shell will check for a executable in each of these files, if it finds it, it will run otherwise it will tell you the program can't be found. As a side note this is the reason why when you run an executable not in one of these PATH files you must do,
./program
this is specifying a relative path to the executable file, the current directory that you are in.
So for you, you installed pip to this directory:
/Library/Python/2.7/site-packages
chances are the above echo statement did not include this file, if it did then you have another problem. What you need to do is to update your PATH variable to include this directory as well. To do this you add an export statement to your .bash_profile (or .bashrc on Linux) in your home directory (this is a hidden file) that includes your current path variables (so you will still be able to run everything installed in the proper place) and this new directory that you installed pip to. To do this add this line to the end of your .bash_profile
export PATH=${PATH}:/Library/Python/2.7/site-packages
and you should be good to go. However before it will take effect you need to close and open your terminal window again or run source .bash_profile. You can verify this worked by running the echo command above, it should return the same thing but this time with /Library/Python/2.7/site-packages appended to the end.
Note: By the way the which command that you were told to run in the comments locates a program within the users path, which is why it did not return anything to you. Also since you will probably run into this soon enough there is also a variable called PYTHONPATH (look here) which tells python where to look to import modules. You should set this to whatever directory you have pip installing modules to if it is not already set.
Install python3 first, then use pip3 to install packages.
brew install python
python3 will be installed, and pip is shipped with it. To use pip to install some package, run the following
pip3 install package
Notice it's pip3 because you want to use python3.
My same answer here
to run the command, it works
sudo easy_install pip

Categories

Resources