pip not running with Python 3.5 - python-3.x

I have installed Python 3.5 and Pip but When I am type pip or pip3 in console, i get this error
The folder you are executing pip from can no longer be found.
If I run pwd, I get
/home/zahid
Pip was installed using
sudo python /usr/local/lib/python3.5/site-packages/easy_install.py pip
and output that I got was
[sudo] password for zahid:
Searching for pip
Best match: pip 8.1.1
Adding pip 8.1.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3.5 script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Using /usr/local/lib/python3.5/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
Can anyone tell me what is going on here
which python3 returns
/usr/bin/python3
which pip returns
/usr/local/bin/pip
which pip3 returns
/usr/local/bin/pip3
echo $PYTHONPATH returns
nothing blank
Regards

Please close this terminal and open a new terminal. You may have deleted some files inadvertently. As a result the terminal is unable to locate some links or environment variables. I faced the same issue. In a new terminal everything went fine.

I had this error on my Mac and restarting fixed this problem for me.

Does sudo pip work?
If so, check to make sure your profile isn't messed up. Check your path variable using the echo command with something like echo $PATH
You need to make sure /usr/local/bin is present in your user profile.
If not, did you install pip into 3.5 and are you accidentally running some other version of python like python 2?

Create a symbolic link using
ln -s /usr/local/bin/pip /usr/bin/pip
test it by running
pip -V

Related

Installed python package with `pip3`, but when I call it I get "No module named X"

I installed a module like this:
> pip3.8 install mssql-cli
but when I run it I get:
> 3002 ~$ mssql-cli -S 192.168.7.50 -d test-db
/usr/bin/python: No module named mssqlcli
I think mssql-cli is defaulting to the system--default python (2.x). How do I tell it to use python3.8?
Yes, I'm on a Mac. Python 3.8 is installed via Homebrew.
Answering questions from comments:
What does pip3.8 --version say?
3044 ~$ pip3.8 --version
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
And check that which python3.8 points to /usr/local/lib/python3.8/python?
Not exactly. Is that bad?
3048 ~$ ll `which python3.8`
lrwxr-xr-x 1 grantb admin 40 Jul 24 10:57 /usr/local/bin/python3.8# -> ../Cellar/python#3.8/3.8.5/bin/python3.8
The issue is that if you look at the actual mssql-cli file it runs it using the python command. This (on my Mac) defaults to the 2.7 python. There are three solutions:
Add a line in your .bashrc or .bash_profile that says alias python='python3.8'. Note that this will override your python2.7 (which is obsolete anyway).
Edit the last line of the file that comes up with which mssql-cli to say python3.8 -m mssqlcli.main "$#". This has the disadvantage that you aren't really supposed to edit this, and that you'd need to do it every time you update this package, but it does work.
Run each mssql-cli command with the equivalent python3.8 -m mssqlcli.main.
Yet another brave soul caught up in the tangled web of installing Python on a Mac.
Your problem is that homebrew installed a version of Python in /usr/local/Cellar/python#3.8/3.8.5/bin/python3.8. Pip3.8, on the other hand, thinks Python is at /usr/local/lib/python3.8/python, so it installs its packages in that python's site-packages directory.
If you already had python with pip installed when you installed it from the Homebrew bottle, it won't overwrite the links you already had. One solution is to reinstall pip through the correct python.
python3.8 -m pip install -U --force-reinstall pip
This should force a reinstall of pip, and since python3.8 points to Homebrew's Python, it should install pip and pip3 as pointing to that python.

Pip Not recognized as an external command in cmd in windows

When I am trying to install the Python 3.7.1 It installed the Python 3.7.1. I can also check the pip install checkbox. Later I am trying to install pip in cmd. The below error occurs. When I try to see the pip.exe file in Python37/Scripts it shows an empty folder. I don't know what to do and what is the issue. Please help me because it was my study project to do.
Your pip is not setup during installation, you can re-run the python installer and make sure to check the option to install pip or simply access pip using:
python3 -m pip
All commands are the same,so you can install packages like:
python3 -m pip install cython
Hope this works for you!

How to run pip from python3.7.1

I'm having python3.7.1 installed on my Mac, but when I run the command pip --version it shows syntax error. It's said that for python3 and greater versions pip is pre-installed, but why still I'm not able to use pip from python3?
pip might be outdated, check for updates running this command on terminal in your Mac:
pip install -U pip
Also doble check the version you have by running:
python --version
if you get
“Python is not defined”
you will need to reinstall it.
Further reading: Installing Python Modules

virtualenv: cannot import name 'main'

I'm having a little trouble with virtualenv on Mac OS X Yosemite. After I couldn't run virtualenv at all first, I installed Python 3 via brew (previously I installed it via the package on python.org). I linked this installation of python3, updated pip and ran pip3 install virtualenv. When I try to run virtualenv (e.g. $ virtualenv --python=python3 ../virtualenv), I get the following error message.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
File "/usr/local/bin/virtualenv.py", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main'
Can anybody help me with this?
After my upgrade to Fedora 32 I had the same issue which lead me to this question:
ImportError: cannot import name 'main' from 'virtualenv'
In my case I actually seemed to have both /usr/local/bin/virtualenv as well as $HOME/.local/lib/python3.8/site-packages/virtualenv/__init__.py.
Removing the user virtualenv version and reinstalling it into the system with root fixed the issue:
pip uninstall virtualenv
sudo pip install virtualenv
Your virtualenv executable /usr/local/bin/virtualenv is importing the virtualenv package /usr/local/bin/virtualenv.py. My guess is that package is not the one the executable should really be importing. The reason it is choosing that one is because it is in the same directory.
First, check where the real virtualenv package is. In the python3 terminal:
>>> import virtualenv
>>> virtualenv.__file__
If it is not /usr/local/bin/virtualenv.py, then the simplest way to get /usr/local/bin/virtualenv to import it instead of /usr/local/bin/virtualenv.py is to delete /usr/local/bin/virtualenv.py (or so you can easily undo this if it doesn't work, simply rename virtualenv.py to something else like xvirtualenvx.py).
I received this error after upgrading Ubuntu 18.04 LTS to 20.04 LTS. So there were two problems all at once. First the python version was still running 2.x and doing a simple update or try to uninstall (apt-get remove virtualenv) of virtualenv did not help at all. But I found a solution. First let 20.04 LTS 'know' the times of using old python is over:
sudo apt-get install python-is-python3
Then test it and open a console to get the version string with python -V; by now it should be showing something like Python 3.8.5. Fine.
Next step is to solve the virtualenv problem. I tried to find out, which executable was run with which virtualenv and it showed: $HOME/.local/bin/virtualenv. Hmmkay, somehow the system wasn't using the /usr/bin/virtualenv executable. I thought maybe I let the directory become invisible (a.k.a. renaming) and maybe the system will go on a hunt for an alternative virtualenv running:
mv $HOME/.local/bin/virtualenv /home/USER/.local/bin/virtualenv_OLD
Then I simply changed into a playground-directory and ran virtualenv donaldknuth and behold - it worked. To be sure I ran another which virtualenv and the system returned a /usr/bin/virtualenv. Last check to do was activating the new virtual environment:
source $HOME/playground/donaldknuth/bin/activate
The terminal changed and it worked fine. Solution
EDIT:
Based on Pierre B.'s suggestion you may have to restart your Shell. The command hash -d virtualenv will delete the stored location of virtualenv from the shell's cache and determine the correct path right now. (Sources: https://www.computerhope.com/unix/bash/hash.htm, https://unix.stackexchange.com/questions/5609/how-do-i-clear-bashs-cache-of-paths-to-executables)
Similarly to some others here, I had multiple installations of virtualenv. Not sure where the extra one came from, but I had these two:
/usr/local/bin/virtualenv
/usr/bin/virtualenv
One is from apt install of virtualenv, the other from pip install of virtualenv.
This happened when upgrading to Ubuntu 20.04.
On Linux Mint 20, I had to switch default Python interpreter to python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
Then remove existing virtualenv and reinstall via pip and python3:
rm ~/.local/bin/virtualenv
apt remove python3-virtualenv
sudo pip install virtualenv

Pip won't install into python 3 when using homebrew python?

So I've got a virtualenv I've created using pyvenv-3.3, which I thought set up pip to install things into the virtualenv's path. However, I get the following outputs after I've activated by virtualenv:
$ pip --version
pip 1.4.1 from /usr/local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg (python 2.7)
pip-3.3 --version
pip 1.4.1 from /usr/local/lib/python3.3/site-packages/pip-1.4.1-py3.3.egg (python 3.3)
This is all fine and good, but then my sys.path is this:
['',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python33.zip',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload',
'/Users/alexgolec/Documents/gutenberg/virtualenv/lib/python3.3/site-packages']
Most notably, the whole site-packages directory is outright missing. Furthermore, this output indicates to me that I'm probably using a python that installed through homebrew at some point. Most infuriatingly, none of the directories in my sys.path are compatible with pip.
Any thoughts on remedies? I won't manually edit my sys.path, but maybe there's some configuration with pip I can do?
Install virtualenvwrapper (makes using virtualenv so much easier):
pip install virtualenvwrapper
.. and then try this:
mkvirtualenv <your_env> -p /usr/local/bin/python3
Where homebrew sticks python is different from where your system has it. You can run the following to see what I'm talking about:
which python
which python3

Resources