I had python2 installed in my ubuntu (19.04) and I wanted to get it upgraded to 3.7. I installed the 3.7 but still the version showed as 2.7. but I could run python3 and go to the console and python3.7 executable was available in /usr/bin. Did try all the tricks available in internet without any luck. then I decided to delete python2.7 executable from the /usr/bin and now I cannot even run pip as it tries to find the deleted 2.7 I guess. Getting the following message.
bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory
I don't know why it's still trying to find 2.7 like ex girl friend when 3.7 is installed and available in the machine.
Did you set up a path for python 3.7 in your .bashrc file? If not, try that and that should help.
Usually a path is something like:
$ export PATH=$HOME/Nek5000/bin:$PATH
First, run an update to make sure that there aren’t newer versions of the required packages.
sudo apt update --fix-missing
Next, you can try forcing Apt to look for and correct any missing dependencies or broken packages. This will actually install any missing packages and repair existing installs.
sudo apt install -f
(Source)
Also, always remember - never install directly in global environment. You should always create a local environment first(i recommend venv) as there are very high chances you can break something globally.
You can create a local environment by -
python3 -m venv tutorial-env
where tutorial-env is the name of your environment.
To activate this environment, you should run
source tutorial-tutorial-env/bin/activate
I'm using a remote server, which some others use together.
There are several versions of python installed.
I need python 3.6 version, and I can run it with /bin/python3.6 command.
And I also want to make a virtualenv of the version, so I tried /bin/python3.6 -m pip --version
But it showed
/bin/python3.6: No module named pip
When I checked the lib directory, ll /usr/lib/python3.6/site-packages/
total 0 drwxr-xr-x 2 root root 6 Dec 20 2017 __pycache__
It seems that the server has python3.6, but misses pip for that, right?
How can I resolve this, with the minimum modification?
The server is centos7.
Any thought or comment appreciated :)
As drum mentioned at the comment, I installed pip referring to pip.pypa.io/en/stable/installing.
I ran the python file with /usr/bin/python3.6 get-pip.py.
After installing virtualenv, I faced virtualenv not found error.
You can solve the above error with the following link.(It was a path issue) Virtualenv Command Not Found
In case you don't want to modify the system Python you can just use the zipapp version of virtualenv to create a virtual environment at some arbitrary location with latest pip included (see https://virtualenv.pypa.io/en/latest/installation.html#via-zipapp).
wget https://bootstrap.pypa.io/virtualenv/virtualenv.pyz
python3.6 /full/path/to/downloaded/virtualenv.pyz ~/virtualenv
~/virtualenv/bin/python -m pip list
That's probably the minimum harmful modification, and ensure that messing with the system python does not break your system python applications/environment.
I am experiencing an odd python thing! I can only use python 2; all other pythons (python3.4, -3.5) are gone; They exist in usr/bin, but I can't use them. For example, usr/bin/python3.4 invokes pyhton2.7. Two days ago everything was normal; I was using python3.4 just fine. All I did in last two days was to install a flask environment and I also purged teamviewer from my ubuntu.
One quick way to solve it, if you have Python 3 installed is typing python3.
Also, check this link, it probably solves your problem https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
Check links in /usr/bin
ls -al | grep python
All python interpreters must be linked with our executable files.
Call python 3 with version, for example:
python3.4
Do not change symbolik link from python to python3, this can crash system scripts.
Install and use virtualenvwrapper:
pip install virtualenvwrapper
Check virtualenvwrapper location:
whereis virtualenvwrapper.sh
Add into you BASH config calling virtualenvwrapper and use it for creating virtual environment with python 3:
mkvirtualenv myvenv --python=/usr/bin/python3.4
Activate virtualenv and install required packages (root privilegies NOT required!):
workon myvenv
pip install flask
Call IDE from terminal with activated virtual environment for correct PATH working.
Enjoy!
Here is how I fixed it:
sudo apt-get install --reinstall python3.4
Now, everything is back to normal.
I've installed virtualenv via pip and get this error after creating a new environment:
selenium:~ auser$ virtualenv new
New python executable in new/bin/python
ERROR: The executable new/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/System/Library/Frameworks/Python.framework/ Versions/2.6' (should be '/Users/user/new')
ERROR: virtualenv is not compatible with this system or executable
In my environment:
PYTHONPATH=/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
PATH=/System/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
How can I repair this?
Thanks.
Just in case there's someone still seeking for the answer.
I ran into this same problem just today and realized since I already have Anaconda installed, I should not have used pip install virtualenv to install virtual environment as this would give me the error message when trying to initiate it later. Instead, I tried conda install virtualenv then entered virtualenv env_mysite and problem solved.
Like #RyanWilcox mentioned, you might be inadvertently pointing virtualenv to the wrong Python installation. Virtualenv comes with a -p flag to let you specify which interpreter to use.
In my case,
virtualenv test_env
threw the same error as yours, while
virtualenv -p python test_env
worked perfectly.
If you call virtualenv -h, the documentation for the -p flag will tell you which python it thinks it should be using; if it looks wonky, try passing -p python. For reference, I'm on virtualenv 1.11.6.
In case anyone in the future runs into this problem - this is caused by your default Python distribution being conda. Conda has it's own virtual env set up process but if you have the conda distribution of python and still wish to use virtualenv here's how:
Find the other python distribution on your machine: ls -ls /usr/bin/python*
Take note of the availble python version that is not conda and run the code below (note for python 3 and above you have to upgrade virtualenv first): virtualenv -p python2.7(or your python version) flaskapp
I've run across this problem myself. I wrote down the instructions in a README, which I have pasted below....
I have found there are two things that work:
Make sure you're running the latest virtualenv (1.5.1, of this writting)
If you're using a non system Python as your standard Python (which python to check) Forcefully use the System supplied one.
Instead of virtualenv thing use /usr/bin/python2.6 PATH/TO/VIRTUALENV thing (or whatever which
python returned to you - this is what it did for me when I ran into this issue)
I had the same problem and as I see it now, it was caused by a messy Python installation. I have OS X installed for over a year since I bought a new laptop and I have already installed and reinstalled Python for several times using different sources (official binaries, homebrew, official binaries + hand-made adjustments as described here). Don't ask me why I did that, I'm just a miserable newbie believing everything will fix itself after being re-installed.
So, I had a number of different Pythons installed here and there as well as many hardlinks pointing at them inconsistently. Eventually I got sick of all of them and reinstalled OS X carefully cleaned the system from all the Pythons I found using find utility. Also, I have unlinked all the links pointing to whatever Python from everywhere. Then I've installed a fresh Python using homebrew, installed virtualenv and everything works as a charm now.
So, my recipe is:
sudo find / -iname "python*" > python.log
Then analyze this file, remove and unlink everything related to the version of Python you need, reinstall it (I did it with homebrew, maybe official installation will also work) and enjoy. Make sure you unlink everything python-related from /usr/bin and /usr/local/bin as well as remove all the instances of Frameworks/Python.framework/Versions/<Your.Version> in /Library and /System/Library.
It may be a dirty hack, but it worked for me. I prefer not to keep any system-wide Python libraries except pip and virtualenv and create virtual environments for all of my projects, so I do not care about removing the important libraries. If you don't want to remove everything, still try to understand whether your Pythons are, what links point to them and from where. Then think what may cause the problem and fix it.
I ran into a variation of this "not functioning" error.
I was trying to create an environment in a folder that included the path ".../Programming/Developing..." which is actually "/Users/eric/Documents/Programming:Developing/"
and got this error:
ImportError: No module named site
ERROR: The executable env/bin/python2.7 is not functioning
ERROR: It thinks sys.prefix is u'/Users/eric/Documents/Programming:Developing/heroku' (should be u'/Users/eric/Documents/Programming:Developing/heroku/env')
ERROR: virtualenv is not compatible with this system or executable
I tried the same in a different folder and it worked fine, no errors and env/bin has what I expect (activate, etc.).
I got the same problem and I found that it happens when you do not specify the python executable name properly. So for python 2x, for example:
virtualenv --system-site-packages -p python mysite
But for python 3.6 you need to specify the executable name like python3.6
virtualenv --system-site-packages -p python3.6 mysite
On on OSX 10.6.8 leopard, after having "upgraded" to Lion, then downgrading again (ouch - AVOID!), I went through the Wolf Paulus method a few months ago, completely ignorant of python. Deleted python 2.7 altogether and "replaced" it with 3.something. My FTP program stopped working (Fetch) and who knows what else relies on Python 2.7. So at that point I downloaded the latest version of 2.7 from python.org and it's installer got me up and running - until i tried to use virtualenv.
What seems to have worked for me this time was totally deleting Python 2.7 with this code:
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
removing all the links with this code:
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config
I had tried to install python with homebrew, but apparently it will not work unless all of XTools is installed, which I have been avoiding, since the version of XTools compatible with 10.6 is ancient and 4GB and mostly all I need is GCC, the compiler, which you can get here.
So I just installed with the latest download from python.org.
Then had to reinstall easy_install, pip, virtualenv.
Definitely wondering when it will be time for a new laptop, but there's a lot to be said for buying fewer pieces of hardware (slave labor, unethical mining, etc).
The above solutions failed for me, but the following worked:
python3 -m venv --without-pip <ENVIRONMENT_NAME>
. <ENVIRONMENT_NAME>/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
It's hacky, but yes, the core problem really did just seem to be pip.
I did the following steps to get virtualenv working :
Update virtualenv as follows :
==> sudo pip install --upgrade virtualenv
Initialize python3 virtualenv :
==> virtualenv -p python3 venv
I had this same issue, and I can confirm that the problem was with an outdated virtualenv.py file.
It was not necessary to do a whole install --upgrade.
Replacing the virtualenv.py file with the most recent version sufficed.
I also had this problem, and I tried the following method which worked for me:
conda install virtualenv
virtualenv --system-site-packages /anaconda/envs/tensorflow (here envs keeps all the virtual environments made by user)
source /anaconda/envs/tensorflow/bin/activate
Hope it's helpful.
I had this same issue when trying to install py2.7 on a newer system. The root issue was that virtualenv was part of py3.7 and thus was not compatible:
$ virtualenv -p python2.7 env
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in /Users/blah/env/bin/python
ERROR: The executable /Users/blah/env/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/Library/Frameworks/Python.framework/Versions/2.7' (should be u'/Users/blah/env')
ERROR: virtualenv is not compatible with this system or executable
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenv
# install proper version of virtualenv
$ pip2.7 install virtualenv
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv -p python2.7 env
$ . ./env/bin/activate
(env) $
Open terminal and type /Library/Frameworks/Python.framework/Versions/
then type ls /Library/Frameworks/Python.framework/Versions/2.7/bin/
if you are using Python2(or any other else).
Edit ~/.bash_profile and add the following line:
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/
cat ~/.bash_profile
In my case the content of ~/.bash_profile is as follows:
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/
Now the virtualenv command should work.
If you continue to have trouble with virtualenv, you might try pythonbrew, instead. It's an alternate solution to the same problem. It works more like Ruby's rvm: It builds and creates an entire instance of Python, under $HOME/.pythonbrew, and then sets up some bash functions that allow you to switch easily between versions. Where virtualenv shadows the system version of Python, using symbolic links as part of its solution, pythonbrew builds entirely self-contained installations of Python.
I used virtualenv for years. It's a decent solution, but I've switched to pythonbrew lately. Having completely self-contained Python instances means that installing a new one takes awhile (since pythonbrew actually compiles Python from scratch), but the self-contained nature of each installation appeals to me. And disk is cheap.
I am running RHEL5 , and i have python 2.4 installed on it.Please dont ask why the native version?
My question is that in my home directory i want to install python2.6 with selected packages only and also most importantly i dont want any of the library os or any other which deals with system calls or mail box preferences(sending mail to be prohibited).Is it possible to install a python version with selected libraries only.
So now on the system python 2.4 and selected libraries of 2.6 exists
This may not be quite what you're looking for... but the following steps will accomplish something similar to this (if you have root access). The below steps assume you are on i386 architecture.
1) Install Python 2.6 in parallel on your system (requires root). It is available at the EPEL repository:
$ rpm -i http://download.fedora.redhat.com/pub/epel/5/i386/python26-2.6.5-6.el5.i386.rpm
2) Install setuptools by running (again as root):
$ curl http://peak.telecommunity.com/dist/ez_setup.py | python26
3) Install virtualenv (http://pypi.python.org/pypi/virtualenv):
$ easy_install-2.6 virtualenv
4) From your home directory, create a new python environment:
$ cd ~
$ virtualenv --no-site-packages my-env
5) Activate the environment:
$ source my-env/bin/activate
You can now use easy_install to install whatever packages you want, remove anything you don't want from ~/my-env/lib/python26/site-packages, etc.
To let you know you are working in the virtual environment, your prompt will look like this:
[(my-env)you#host ~]$
One thing you have to be careful about is python scripts that start with #!/usr/bin/python, as they will not use the environment version. To ensure that the environment version is used, execute your script like this:
$ python your-script.py
Or you can specifically specify your environment version in your scripts:
#!/home/your-name/my-env/bin/python
Try ActivePython - it installs to an isolated directory (eg: /opt/ActivePython-2.6), and you can use PyPM to install third-party packages.