Virtualenv is installing with wrong version of Python - python

I recently have started learning python and have run into an issue.
When I run python on my mac without virtualenv, the version number is Python 2.7.5. Unfortunately, when I go into my virtualenv, and run Python, the version number is Python 2.6.1.
I tried, creating another virtualenv using:
virtualenv -p /usr/bin/python2.7 newdev
but got: The executable /usr/bin/python2.7 (from --python=/usr/bin/python2.7) does not exist

You have to specify the executable, not the whole path. For example:
mkvirtualenv --python=python3 mynewenv

virtualenv --python=python3 mynewenv

Related

problems comes while creating virtualenv

I have installed python 3.10.2, while creating virtualenv
I did pip install virtualenv. then I create myenv (virtualenv mypython), but I got error like this. could you please help me what do I do
the error is :
C:\Users\ARROWIN PHOTOGRAPHY\Felix\djangoProject>virtualenv mypython
'virtualenv' is not recognized as an internal or external command,
operable program or batch file.
In python3 is better to use venv instead. Here are the steps to create your environment:
In your project directory, open the terminal:
python3 -m venv venv
Then:
source venv/bin/activate
Make sure that you have set up the python PATH variables correctly and that in your path e.g. ..\AppData\Local\Programs\Python\Python39\Scripts you can locate the python executable virtualenv.exe
If you are using multiple python versions on your local machine be careful while using PIP install. It is better to use the command pip3.x install ... (x is meant to be a specific version of pip e.g. pip3.9) so you can be sure you installed the virtualenv in the correct version of Python, and afterward, you can also select a specific python version when using virtualenv by virtualenv env -p pythonxx the xx is meant as a python version.

virtualenv ERROR: the executable in env/bin/python is not functioning

The Problem
I am having great difficulty getting virtualenv to work on my OSX machine. When I run virtualenv env I get the error:
New python executable in env/bin/python
ERROR: The executable env/bin/python is not functioning
ERROR: It thinks sys.prefix is '/Users/tylerwendlandt/Documents/Courses/cmput_401' (should be '/Users/tylerwendlandt/Documents/Courses/cmput_401/env')
ERROR: virtualenv is not compatible with this system or executable
I tried looking around for solutions - but I can't seem to get it to work. I don't work with python very often, so this is mostly unfamiliar to me. I attempted to include the needed information, please let me know if more is needed. I appreciate any help - thank you.
Some info:
which python
/Users/tylerwendlandt/anaconda/envs/ualbertacro/bin/python
python --version
Python 3.4.3 :: Continuum Analytics, Inc.
which pip
/Users/tylerwendlandt/anaconda/envs/ualbertacro/bin/pip
pip --version
pip 7.1.2 from /Users/tylerwendlandt/anaconda/envs/ualbertacro/lib/python3.4/site-packages (python 3.4)
which virtualenv
/Users/tylerwendlandt/anaconda/envs/ualbertacro/bin/virtualenv
virtualenv --version
13.1.2
update virtualenv version
pip install --upgrade virtualenv
So basically you are using conda rather than the inbuilt python of mac. So you should do following things:
pip uninstall virtualenv
conda install virtualenv
Then it will work fine.
Did you try
virtualenv -p python env
I think you have path issue, is there something in your PYTHONPATH variable from second error line? If your PYTHONPATH has the first directory in the error line, change it to second one and try again.

installing python2.7 using virtualenv in ubuntu-lucid

I have python2.6 on ubuntu lucid.I have installed virtualenv 1.8.2 for python2.6 .There is the virtualenv-1.8.2-py2.6.egg in /usr/local/lib/python2.6/dist-packages folder.
I want to install python2.7 using virtualenv so I can test some of my code.How do I go about this?I tried
virtualenv venv27 --distribute --no-site-packages --python=python2.7
which gave an error like
The executable python2.7 (from --python=python2.7) does not exist
Please tell me how to go about this? Do I have to upgrade my O.S ?
virtualenv does not download or install Python (different from Ruby's rvm).
When you specify what python you want virtualenv to be based on (--python=PYTHON_BIN), that executable must exist. virtualenv uses that python installation to create its symlinks, shebangs, and everything.
As #Blender and #Dikei told you, you must have Python 2.7 before you create your virtualenv.

How to use Python virtualenv

The scenario is: I am on Ubuntu 11 which comes with Python 2.7, I want to run Mozilla JetPack which supports Python 2.5/2.6 and Google App Engine which only supports Python 2.5.
Read that its not a good idea to remove Python 2.7 as Ubuntu maybe using it. So the correct way is to use virtualenv. But I am quite lost using it. I installed Python 2.5 in /usr/local/python25 following this guide
I tried
jiewmeng#JM:/usr/local/python25/bin$ ./python --version
Python 2.5.5
jiewmeng#JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
./python: can't open file 'virtualenv': [Errno 2] No such file or directory
then the below works but I will be using Python 2.7
jiewmeng#JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
New python executable in /works/tmp/test/bin/python
Installing distribute.................................................................................................................................................................................done.
jiewmeng#JM:/usr/local/python25/bin$ cd /works/tmp/test/bin
jiewmeng#JM:/works/tmp/test/bin$ ls
activate activate_this.py easy_install easy_install-2.7 pip python
jiewmeng#JM:/works/tmp/test/bin$ ./python --version
Python 2.7.1+
Also, how do I then run Mozilla JetPack or Google App Engine with this version of Python? Sorry I am new to Python (and Linux/Ubuntu)
Outline:
First cd to /usr/local/python25/bin
Download setuptools for Python2.5 (setuptools-0.6c11-py2.5.egg)
Install it (sh setuptools-0.6c11-py2.5.egg).
Now install pip (easy_install pip).
Install virtualenv and virtualenvwrapper using pip (pip install v... etc.).
Configure WORKON_HOME for virtualenv wrapper to work (export WORKON_HOME = $HOME/.virtualenvs). You can use any other directory you want (not just $HOME/.virtualenvs). Just make sure to use the full path.
Now create a virtualenv (mkvirtualenv foobar).
Switch to the new virtualenv (workon foobar).
Now install GAE, JetPack and whatever you want using pip install blah
Why did your install not work?
Looks like you did not install virtualenv for Python2.5. Hence this will not work.
jiewmeng#JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
You can check by running ls command in that directory. I suspect you won't find virtualenv file there.
However this worked for you.
jiewmeng#JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
Because it is using the virtualenv file for system default Python2.7. You can check which virtualenv and opening the virtualenv script. You'll see that the #! will point to system default python.
So you need to install the easy_install and pip for Python 2.5 before you can create virtualenv for Python 2.5. Just follow the steps outlined above.
You don't need to do anything fancy outside the virtualenv wrapper. Just use the --python=python2.5 flag (check out the man page for virtualenv form more). It does not matter what version you install it with, you just have to select the right executable for python in the virtual environment.
e.g. mkvirtualenv --python=python2.5 --distribute python25 if the python flag fails, either add a symlink (ln -s) to python25 in your $PATH or use the full path name on the python flag.
Also, default for multiple python installations is to have, for all 'altinstall' versions, a separate python and easy_install. So, for example: python2.5 ,easy_install-2.5 ,python2.6, easy_install-2.6 etc.

how to get venv to point to older python version

I am trying to clone and run a project on my mac.
but on the installation options I have to run:
pip install -r requirements.txt
I get an error and I am pretty sure its because the project runs on python 2.7 while my venv runs on 3.4
(venv)/*
$ python --version
Python 3.4.3
however when I am outside of venv I run am back onto the correct python version:
$ python --version
Python 2.7.6
WHy is venv running 3.4? How can I change venv to not run 3.4 and just run the 2.7
Do I have to update an environment or venv variable on my system? I can't find where python is in my system. Also any advice on what commands to run would be appreciated as I am a bit new to python/django.
perhaps the pip I have in venv is wrong, idk. Any help is appreciated.
You can use the option -p to specify, which version should be used, when you create the virtual environment.
For example:
virtualenv -p python2.7 venv

Categories