I have python 2.7 installed on mac and I would like to use the CRYPTO module, but it doesn't support so installed home-brew and then downloaded python 2.7.9. I changed the path on ~/.bash_profile to /usr/local/bin
Yet, when I try which python it uses the default one.
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
I suggest you use virtualenv to create a virtual enviroment for your project, which provides you isolated Python environment specific to one Python interpreter.
Official Python package installation guide.
Quick example:
virtualenv -p /path/to/my/python venv
source venv/bin/activate
pip install pycrypto
If you need to activate virtualenv in your .bash_profile add line (. instead of source):
. /Users/you/venv/bin/activate
Related
I know there are some similar questions,but it is really hard for me to finish it.
I'm trying to create a virtualenv with python 3.7.7 in windows.
I have a downloaded python 3.7.7
C:\Users\willi\AppData\Local\Programs\Python\python-3.7.8-embed-amd64
Since I can built a virtualenv using:
python3 -m venv myenv
So I tried to modify it ,so that it can match specific python version:
python3 -m C:\Users\willi\AppData\Local\Programs\Python\python-3.7.8-embed-amd64\python.exe myenv
But it failed:
ModuleNotFoundError: No module named 'C:\\Users\\willi\\AppData\\Local\\Programs\\Python\\python-3')
Any friends can teach me how to build a virtualenv with python 3.7.7?
I think you haven't installed virtual environment in your local python
pip install virtualenv
and follow your steps. Stil, find the error. Try doing below methods, I think you will get your answer-
in command prompt
pip install virtualenv
go to the location, where you want to create your environment
cd location
virtualenv project_env_name
Now, you will find a python env in the desired location, Then go to scripts
cd project_env_name/scripts
activate
You will enter the environment you created. while leaving the environment, do
deactivate
To leave the environment.
This method works if you want to create the same python version environment as python version in your machine.
If you want to create an environment of the different version, you need to install the python of that version.
To create a virtual environment using virtualenv you can specify the Python release and point version like so:
virtualenv --python=python3.6 .venv
How can I achieve this using Python3's venv module (as in python3 -m venv .newvenv)? According to the documentation using venv is the recommended way to create virtual environments but I didn't see how I can choose a virtual environement with a specific Python version.
Run venv with whatever Python installation you want to use for the new virtual environment. For example, if you would run your Python 3.6 installation with python3.6, then
python3.6 -m venv whatever
would be how you create a Python 3.6 virtual environment.
I thought to add to this answer when one is using pyenv. In my workflow I use pyenv to have multiple python versions but not to manage virtualenvs. I rather have my python virtual environment in the project's root. With pyenv one can install multiple python versions by running pyenv install 3.8.10 and after that pyenv install 3.9.0. When you run pyenv versions you should get something similar to this
system
* 3.8.10 (set by /Users/<user>/.pyenv/version)
3.8.10/envs/python-test.venv
3.9.0
When working on a project and choosing what python version should be used in that project you can do the following.
$ mkdir my_project && cd my_project
$ pyenv global <version>
$ python --version // should be the version you set as global
$ python -m venv .venv
$ source .venv/bin/activate
I was able to avoid error mentioned in the comments by using the option --without-pip. Then after activating the venv, I installed pip manually with the get-pip.py script.
Is it possible to have a virtual environment setup with python 3 if my OS has python 2.7 installed, I am using "$ virtualenv python3env -p python3" but its trying to look for a PATH for python3 on my system. Is there a work around for this problem?
install python3, DON'T delete your python2
after installing python3, make sure the to add the directory to PATH
change the binary(python,pythonw) inside python3 to python3/pythonw3
try to setup virtual environment using the same command in your post and you should now created a python3 virtual environment
Presently we have a big-data cluster built using Cloudera-Virtual machines. By default the Python version on the VM is 2.7.
For one of my programs I need Python 3.6. My team is very skeptical about 2 installations and afraid of breaking existing cluster/VM. I was planning to follow this article and install 2 versions https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4
Is there a way "I can package Python 3.6" version in my project, and set the Python home path to my project folder, so that there is no installation that needs to be done on the existing Virtual machine?
Since we have to download python and build source for the Unix version, I want to skip this part on VM, and instead ship the folder which has Python 3.6
It seems that miniconda is what you need.
using it you can manage multiple python environments with different versions of python.
to install miniconda3 just run:
# this will download & install miniconda3 on your home dir
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -p ~/miniconda3
then, create new python3.6 env:
conda create -y -n myproject 'python>3.6'
now, enter the new python3.6 env
source activate myproject
python3
miniconda can also install python packages, including pip packages and compiled packages. you can also copy envs from one machine to another. I encourage you to take a deeper look into it.
ShmulikA's suggestion is pretty good.
Here I'd like to add another one - I use Python 2.7.x, but for few prototypes, I had to go with Python 3.x. For this I used the pyenv utility.
Once installed, all you have to do is:
pyenv install 3.x.x
Can list all the available Python variants:
pyenv versions
To use the specific version, while at the project root, execute the following:
pyenv local 3.x.x
It'll create a file .python-version at the project root, having the version as it's content:
[nahmed#localhost ~]$ cat some-project/.python-version
3.5.2
Example:
[nahmed#localhost ~]$ pyenv versions
* system (set by /home/nahmed/.pyenv/version)
3.5.2
3.5.2/envs/venv_scrapy
venv_scrapy
[nahmed#localhost ~]$ pyenv local 3.5.2
[nahmed#localhost ~]$ pyenv versions
system
* 3.5.2 (set by /home/nahmed/.python-version)
3.5.2/envs/venv_scrapy
venv_scrapy
I found it very simple to use.
Here's a post regarding the installation and basic usage (blog post by me).
For the part:
Since we have to download python and build source for the Unix
version, I want to skip this part on VM, and instead ship the folder
which has Python 3.6
You might look into ways to embed Python interpreter with your Python application:
And for both Windows and Linux, there's bbfreeze or also pyinstaller
from - SOAnswer.
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.