I have both Python 3.7 and 3.6 installed. But in my profile I set to use 3.6 and this is indeed a version that gets reported by which python3.
$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
I then create virtual env by running python3 -m venv venv
And everything in my venv gets linked to the 3.6. I confirm this with ls -la venv/bin and by inspecting venv/pyvenv.cfg.
I activate the venv virtual environment.
I then install a zappa library with pip install zappa.
And when I run zappa deploy, I get an error that Python 3.7 is not supported. Why would a library use the version of Python that is not configured within the virtualenv and how do I make it use the correct version?
(venv) $ zappa deploy
Traceback (most recent call last):
File "/Users/t/Projects/djzappa/Spheres/venv/bin/zappa", line 7, in <module>
from zappa.cli import handle
File "/Users/t/Projects/djzappa/Spheres/venv/lib/python3.7/site-packages/zappa/__init__.py", line 12, in <module>
raise RuntimeError(err_msg)
RuntimeError: This version of Python (3.7) is not supported!
Zappa (and AWS Lambda) support the following versions of Python: ['2.7', '3.6']
NOTE: I do NOT use virtualenv as everybody is suggesting, and as other existing answers are referring.
Use this when you create environment:
virtualenv --python=/usr/bin/python3.6
But if you want to use venv, first of all, check whether python3 in your terminal refers to the python3.6 as you want.
If not - run your command with the full path to python3.6 instead of sole python3 in python3 -m venv venv.
Edit: why your alias python3 is referring to python3.7 - it probably depends on OS you use and sequence of installation. Hard to say.
As an addition to the accepted answer, be also aware that changing the directory name where your venv is located causes using the default python and pip paths of your system, instead of using the venv one.
The Python version is different from the virtualenv python version and that is why it is complaining.
You can recreate your virtual environment(delete the existing one) and use the following command
virtualenv --python=your python version here venv
Or
mkvirtualenv venv --python=your python version here
if you want to create your virtual environment using mkvirtualenv command.
Related
I am trying to create a virtual enviroment in my ubuntu OS using virtualenv
The command I am using is
virtualenv -p /usr/bin/python3.8.13 py3.8.13_env
The error shown is
FileNotFoundError:[Errno 2]No such file or directory:'/usr/bin/python3.8.13'
I have tried several other python versions but I get the same error
You can see what versions of Python you have by:
ls -l /usr/bin/python*
If you don't provide one then virtualenv will use a default of /usr/bin/python3. On Ubuntu this will be a symlink to a specific version. e.g.
/usr/bin/python3 -> python3.10
So just calling virtualenv like:
virtualenv py3.10_venv
Would create a virtualenv called "py3.10_venv" (a folder) in your current working directory, using Python 3.10 in this example.
If you have other versions (shown by the ls command above) then you can use those specifically as you are trying to do in your question above.
I'm trying to create new Python virtual environment, but I have problems with pip.
I want my virtual environment to run on Python 3.10, but my default system Python version is 3.9.5. So I downloaded Python 3.10 with
sudo apt-get install python3.10
and then i run
python3 -m virtualenv venv --python=python3.10
to create virtual environment.
The problem is, when I try to use pip I get an error:
Traceback (most recent call last):
File "/home/<my user name>/venv/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
I tried running
python -m ensurepip --upgrade
but got an error:
/home/pablo/venv/bin/python: No module named ensurepip
Also running whereis pip shows, that there are some pips in the virtual environment.
pip: /usr/bin/pip /home/<my user name>/venv/bin/pip3.10 /home/<my user name>/venv/bin/pip /usr/share/man/man1/pip.1.gz
Also, when I create virtual environments with my default python interpreter, everything works perfectly fine.
I would recommend using pyenv with pyenv-virtualenv. In my experience it's just too much work to go manual. Sorry I know this is not a true answer, but having wasted hours and hours on similar issues, I feel like sharing )
your installed binary executable is named as pip3.10(/usr/bin/pip /home//venv/bin/pip3.10). So you should use the same name to call it, just pip wouldn't work. Have you tried that?
I want to run a python script in in-built anaconda environment tensorflow_p36. To check if it is in virtual environment or not, I am using command pip -V.
My first attempt at bash script:
#!/bin/bash
source activate tensorflow_p36
python /home/ec2-user/abc/temp.py
pip -V
Note: tensorflow_p36 being an in-built environment, does not require to be called from specific /env/bin directory. It can be activated from any directory. I think it's a feature of Amazon Deep Learning AMIs.
My second attempt at bash script:
#!/bin/bash
pythonEnv="/home/ec2-user/anaconda3/envs/tensorflow_p36/"
source ${pythonEnv}bin/activate
${pythonEnv}bin/python /home/ec2-user/abc/temp.py
pip -V
Note: When I try to run source /home/ec2-user/anaconda3/envs/tensorflow_p36/bin/activate command in terminal, the environment isn't being activated.
Each time, I am getting the same result:
pip 9.0.1 from /home/ec2-user/anaconda3/lib/python3.6/site-packages (python 3.6)
Whereas, I should be getting:
pip 9.0.1 from /home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages (python 3.6)
Can someone please explain how do I activate virtual environment and run a python script from that environment? I need to use this particular environment because of the dependencies installed in it.
Extra info:
Not sure if it matters, but the tensorflow_p36 is a conda environment, not a virtualenv.
This works with virtualenv. Create environment:
virtualenv -p python 3.6 tensorflow_p36
Then change the script to:
#!/bin/bash
source $HOME/tensorflow_p36/bin/activate
python /home/ec2-user/abc/temp.py
I believe the confusion has to do with the fact that you are using anaconda and not virtualenv to create a python environment. These two tools work differently.
If you are using an EC2 instance, why not to install tensorflow_p36 globally anyway?
I'm having an issue with my awscli version + python versions installed on my Mac.
After several tries following this I managed to have it working, however, if i run aws --version I get aws-cli/1.11.170 Python/2.7.10 Darwin/16.7.0 botocore/1.7.28
This confused me because I thought I had just installed python 3.6, so I decided to run which python, and it returned /usr/bin/python
I was still unsure and after some research I found this:
$which python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Now i'm totally unsure which python version is the "main" one and if it is affecting my awscli, i plan to create a restapi using aws SDK with boto3 for Python.
How can i clean my python install or simply make sure my Mac is ready to work with the aws SDK + python?
PS.: I've tried this to uninstall python 2.6, 2.7 and 3.6 (currently installed on my system i suppose) but nothing really happened.
Thanks in advance for the help!
I would recommend creating a virtual environment to create an isolated environment for all the packages in your project. You can create a virtual environment of a specific python version using the following syntax in your shell:
$ python3.6 -m venv env
One you activate the virtual environment, you can use pip to install packages into your local python instance:
$ source env/bin/activate
(env) $ pip install awscli
Whenever you plan to run your application, or install packages for the project, simply activate the virtual environment.
For more information, see the documentation for the venv module in Python's standard library.
I have a virtualenv created for Python 2.5 and want to "upgrade" it to Python 2.6.
Here is how it was originally set up:
virtualenv --no-site-packages -p python2.5 myenv
I now run virtualenv in the same directory to upgrade:
virtualenv --no-site-packages -p python2.6 myenv
...
Not overwriting existing python script myenv/bin/python (you must use myenv/bin/python2.6)
...
Overwriting myenv/bin/activate with new content
The default python is still 2.5, even though I can also specify 2.6. Is there any way to remove 2.5 entirely and have 'bin/python' point to 2.6 instead?
You can use the Python 2.6 virtualenv to "revirtual" the existing directory. You will have to reinstall all the modules you installed though. I often have a virtual directory for developing a module, and virtualenv the same directory with many versions of Python, and it works just fine. :)
In Python 3.3+ venv supports --upgrade flag
--upgrade Upgrade the environment directory to use this version
of Python, assuming Python has been upgraded in-place.
Usage:
python -m venv --upgrade YOUR_VENV_DIRECTORY
I just upgraded my venv from Python 3.7.x to 3.8 on several projects without any issue.
You should create a new virtualenv using python2.6 and then, after activating the new env, use its python2.6 and its easy_install to install new versions of any site packages you need. Beware that the path name to the virtualenv is hardwired into various files within the environment, so, when you are ready to switch over to it, either change your startup scripts et al to refer to the new virualenv path or be very careful about copying it over to the old directory and modifying the path names inside it.
Install a second Python on CentOS
download python
install to diff local
configure --prefix=/opt/virtualenv/python
make && make install
create virtual env using new python
virtualenv /opt/virtualenv --python=/opt/python276/bin/python
note: if needed it can be done with a different user
chown pyuser -R /opt/virtualenv
su - pyuser
source /opt/virtualenv/bin/activate
python -v
Create virtual env:
virtualenv /opt/virtualenv
su - infograficos
source bin/activate
Install pip with python 2.7 (inside virtualenv)
easy_install pip
If you're using OS X, try this if you want to upgrade Python to a minor-increased version (e.g. 2.7.6 to 2.7.8) while keeping third-party libraries work.
It work for me on 5 different virtual environments with Django installed.
You can simply do this by go to your venv file and change the python path and it's version from pyvenv.cfg like this:enter image description here