Python and pip installation on Mac don't show version? - python

On Mac OS.
Downloaded the Python from their website.
Python -V return Python 2.7.16, and
python3 -V return Python 3.9.4
Installed pip with : python3 get-pip.py, got Successfully installed pip-21.0.1
But when I run pip -V
I get File "/usr/local/bin/pip", line 1.... SyntaxError: invalid syntax
After reading here a lot, i could not understand (in simple words for dumbs) :
How could you "alias" or update python to show/run in version 3+ ?
Why I can't get the pip version if it's installed ?

Use pip as a module instead
% python3 -m pip --version
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Anyone who's interested , what i had to do is to
CD the project on terminal
run python3 -m venv env (this create virtual environment of python3 inside project)
run source env/bin/activate activate it.
now pip --version or python --version will return the right results.
From my basic knowledge i understand that the mac is using python2 which we don't want to interrupt, so we install python3 and create a 'virtual environment' for it inside our project folder, once its in, we can install all other things.
to deactivate (stop the virtual env) we run deactivate

Related

Cannot install pip in python 3 mac OSX Big Sur

I recently installed Python 3 and when I wanted to check the version, it says it is Python 2.7
As I understand it, the new MacOS comes with Python 2.7 so that seems to not be the issue.
So when I want to install pip it keeps saying
command not found
How do I install pip then? Help me please
Try the following command:
pip3 install package-name
If you still get the same error message, refer to the following link to get detailed instructions on pip installation on macOS:
https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
I had almost the same problem, what I did was to install Homebrew first.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
then add it to the path
after that you can install Python 3 by typing the following command :
$ brew install python
to check if Python3 has been installed type :
$ python3 --version
I would get in the habit of using a virtual environment for every project. Treat the stock system installations as an implementation detail of the OS, not something you should be modifying directly.
You can start with something as simple as
# Ignore the system-installed Python 2
python3 -mvenv venv
. venv/bin/activate
Now python and pip will each refer to the correct versions found in the virtual environment.

Why doesn't "python3 [command]" do anything?

I am trying to use pip to install discord.py. When I simply type pip install discord.py, it defaults to 2.7 and complains that it needs 3.4+. When I say python3 -m pip [command], nothing is printed to stdout, and as far as I can tell nothing happens at all. What am I doing wrong?
EDIT: The problem seems to extend to all python3 commands - "python3 --version" doesn't do anything either.
Resolution: I installed Python 3.8.0 earlier today. I restarted my computer, and now the default version has been changed to 3.8.0 and everything's working just fine.
check python version
python3 --version
if it is 3.5+ , good , then do in terminal
python3 go to python prompt
import pip check if pip is there or not if not then install it
in ubuntu run command sudo apt install python3-pip
verify again it is installed or not
then do python3 -m pip install discord.py
try using python3 -m pip3 [command] instead. pip3 is used to install python 3 packages.
I highly recommend using a virtual environment. So if you perform virtualenv -p python3 you will have a python3 environment. Then source bin/activate then you should be able to successfully run pip 3 commands simply by using pip install discord.py. Hope this helps!

Changing default idle (&pip) in a python3 virtual env

I have created a virtual environment for a python3 project.
phil#shuttle:$ python3 -m venv venv
phil#shuttle:$ source venv/bin/activate
(venv) phil#shuttle:$ python -V
Python 3.5.3
(venv) phil#shuttle:$
However, when I am in it, idle still defaults to python 2.7. The idle3 command work fine.
Can I change the default version of idle within the virtual environment (and not outside of it) so that don't keep using the wrong version?
(Supplementary question: do I have to do similar for pip/pip3?)
[Running Ubuntu 17.04]
IDLE is run by python, not the reverse. If you run
(venv) phil#shuttle:$ python -m idlelib
where python is 3.5.3, then that python will start the IDLE that comes with 3.5.3.
I do not have idle or idle3 commands on Windows, so I cannot answer questions about it.
To run pip inside the venv, replace idlelib with pip and add pip arguments. If pip is not installed inside the venv, first run python -m ensurepip and then run pip to upgrade pip.

python3 loading dist-packages from python2 on ubuntu

I have fresh ubuntu 16.04 setup for production.
Initially if when i type
python --version gives me python 2.7 and python3 --version gives me python 3.5
but i want python points to python3 by default, so in my ~/.bashrc
alias python=python3 and source ~/.bashrc,
After that i install pip using sudo apt-get install python-pip and when i type pip --version it prints pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7) instead that i want packages to be installed into and get from /usr/local/lib/python3.5/dist-packages.
I have django application which is written with python3 compatible code.
Update: I want to install other packages which have to load from python3 dist-packages not just pip. I don't want to remove python 2.7 from ubuntu it will break other programs, i thought alias python=python3 would install packages into python3.5 dist-packages as well.
You need to use pip3 as the command.
pip3 install coolModule
Be sure to add to your bash profile.
alias pip3="python3 -m pip"

Unable to upgrade virtualenv with Python3.5 and Python2.7 on the same machine

Python 2.7 is the default version on my RHEL box. I also have Python 3.5 installed and added the following to my .bachrc file:
alias python=/usr/bin/python3.5
I run python -V and it indicates 3.5. All good.
I then run:
pip install --upgrade virtualenv
I get the following error:
No distributions at all found for virtualenv in /usr/local/lib/python2.7/site-packages
I'm wondering why 2.7 is still be referenced?
Thanks.
If you look at the contents of pip you will notice that it's just a Python script, and it has a shebang line (#!) pointing to your old python. Try this
cat $(which pip)
You probably have a pip3.5 program, and you can alias it like this
alias pip=/usr/bin/pip3.5
Otherwise you can always run pip like this
python3.5 -m pip install <package>

Categories

Resources