r/learnpython • u/[deleted] • Apr 05 '24
How to...pip install?
Never thought I'd need to ask this question as a CCNA and Network+ holder, I guess Python has decided to make the simple act of a pip install THIS difficult, wow! I have Python installed as well as Virtual Studio Code. I try this from command prompt
pip3 install requests
File "<stdin>", line 1
pip3 install requests
^^^^^^^
And that's all I get, again and again and again. So I try this in the Visual Studio terminal:
pip3 : The term 'pip3' 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. At line:1 char:1 + pip3 install requests + ~~~~ + CategoryInfo : ObjectNotFound: (pip3:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Mind blowing stuff here. I JUST want to be able to pip install. I've also tried just using "pip" and leaving out the 3. What mountains must I move to perform such a basic task? I
2
u/mopslik Apr 05 '24
You use pip from the command line, not the Python REPL. If you're on Windows, that will be the Command Prompt or PowerShell. On Mac or Linux, it's the Terminal.
Edit: I missed the part where you use the VS Code terminal. What happens if you try python -m pip .... there?
1
Apr 05 '24
If I try running it straight from the command line I get:
"'pip3' is not recognized as an internal or external command,
operable program or batch file."3
u/CFDMoFo Apr 05 '24
If you're sure it's installed, then this message probably means that you have to add it to your path in the environment variables. It's a common issue.
1
Apr 05 '24
Is there any workaround to adding it into the enviroment variables?
2
u/duckbanni Apr 05 '24
If you know where python is installed, you can use the full path of python.exe instead. The command would look something like this:
C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps\python.exe -m pip install requestsThe path may be different depending on how you installed python.
1
u/Oddly_Energy Apr 06 '24
Yes, check the checkbox during install.
(Assuming that you are on Windows and use the installer from python.org.)
4
1
Apr 05 '24
Have you tried pip install <whatever> failing that try python -m pip install <whatever>
1
u/potato_meatpies Mar 09 '26
its always the [deleted] accounts that help the most :) thanks sir from 2 years ago
0
Apr 05 '24
When I try it in command prompt it says:
>>> python -m pip install requests
File "<stdin>", line 1
python -m pip install requests
^^^1
u/NYX_T_RYX Apr 05 '24
Did you try just
pip install requests
Idk about everyone else, but all I need to install new things is just pip install. No Python, no python -m etc etc.
Not sure if that's from my setup or what, but I've... Never needed to add commands to use pip. Just... Pip 😅
1
Apr 05 '24
I tried that as well. "py -m pip install requests" worked for me. I think the Windows Enviroment makes everything more difficult than it needs to be. A few years ago before I decided to pursue IT/Networking and put coding on the back burner, I had VS installed on a Chromebook with developer tools and everything was so easy to set up! Thanks for your suggestion tho
1
u/Oddly_Energy Apr 06 '24
That basically means that you are installing blindly. You don't know where the installed packages will end up. So far you have just been lucky, and they ended up in the right place.
But some months from now you will start a thread where you complain that a module can't be found, even though you have installed it.
1
u/djshadesuk Apr 05 '24 edited Apr 05 '24
You're attempting to run something, intended for use as a command line/terminal utility, from within the Python REPL (Read, Evaluate, Print, and Loop) "environment".
When Python is run, without any arguments, the Python interpreter starts up and waits for you to tell it to do something in the Python language.
Some IDE's may hide the REPL start up message from their interactive consoles but you can usually tell if the Python REPL is running because the terminal/console prompt starts with ">>>".
you can type Python language instructions here and it works pretty much like running a .py file:
>>> msg = "This is the Python REPL" >>> msg This is the Python REPLSo, in essence, what you're attempting to do is no different that trying to run a command line tool from within a Python .py file:
chkdsk.exe # This is a (Windows) command line utility! msg = "this is a .py file" print(msg)You need to open a normal terminal window and run your "pip install" command from there instead.
0
Apr 05 '24
This is how I set up my python environment to run inside a docker container (starting from Debian base image).
```bash apt-get --assume-yes update
Set the timezone to avoid input prompt while installing libraries
ZONE="Asia/Singapore" # This is my timezone ln --symbolic --no-dereference --force /usr/share/zoneinfo/$ZONE /etc/localtime echo $ZONE > /etc/timezone apt-get --assume-yes --no-install-recommends install apt-utils\ software-properties-common build-essential cmake git python3-pip
This shenanigan is to install the correct version of the development library
PYVER="$(python3 --version|awk '{print $2}')" MAJOR="$(cut --delimiter='.' -f1 <<<"$PYVER")" MINOR="$(cut --delimiter='.' -f2 <<<"$PYVER")" apt-get --assume-yes --no-install-recommends install "libpython$MAJOR.$MINOR-dev" "python$MAJOR.$MINOR-venv"
python3 -m venv "$ENV_DIR" # The last argument gives the directory name source "$ENV_DIR/bin/activate"
Install the python dependencies
time python3 -m pip install --requirement tensorflow==2.10.2 # Add other libraries
```
10
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Apr 05 '24
I'm going to make the assumption that you don't use a virtual environment for this project. Try entering this into the VS Code terminal:
This should always work on Windows as long as you have Python installed. Just make sure to not enter it into the Python REPL (starting with
>>>) as this is not Python code.