I want to install django, but my system which it's os is mac has python 2.6 which can't support django. so I installed python 2.7 but at that time when I typed python in terminal it response the version is 2.6 after searching I change it to python 2.7 where both of them are still on my computer, when I want to install django it still install it for 2.6 so I decide to install virtual environment but when I create a new environment using "virtualenv venv" it produce environment with python version 2.6! I really confused what should I do to create virtual environment with python 2.7?
The short answer is that you can edit the PATH in ~/.bash_profile to make sure that path for python 2.7 is in front of 2.6 version.
It is a good/common practice to not touch the system python on MAC OS and install a latest version using homebrew. After you installed brew you can install python by:
brew install python
Homebrew will take care of the PATH. After that you will be able to install packages and control virtual environments with your 2.7 installation.
You can specify your python interpreter as a prefix to virtualenv_install
Refer to this post: Is it possible to install another version of Python to Virtualenv?
What I mean to say is create a new virtual env with the correct python interpreter by specifying it as such:
mkdir virtualenvs
cd virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/<user>/.localpython/bin/python2.7
(See the stackoverflow post I mentioned)
Related
I'm using msys2 for my dev environment on Windows 10. It's great, and this is the first roadblock I've come up against.
Specifically I'm trying to install some packages that won't allow me to via pip because my platform is incorrect. They require a 3.6 platform and msys2 comes with 3.7
I tried pyenv-win, but that wouldn't seem to work within cmder and it also installed some full windows installers of python 3.6.
Is there a recommended way to get another version of python installed using the msys ecosystem of command lines?
I know you want to use msys2, but you should reconsider, the majority of implementation don’t use msys2. multiple versions and multiple environments can get complicated. If you choose to go forward in a more standard way, you could use what I have written below
You can’t create a virtual env with a version of python that isn’t install in your system.
Downloaded and install the version of python you want to use, from https://www.python.org/
Create a project folder
Create a venv calling the newly installed version of python
venv is part of the standard library
c:\>python -3.x -m venv c:\path\to\myenv
it created a copy of the python executable in the newly created venv
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Activate the new env
c:\> c:\path\to\myenv\Scripts\activate.bat
(venv) path\to\myenv>
Once activated you can pip install
(venv) path\to\myenv> pip install [package.name]
(venv) path\to\myenv> pip list
Any script you run from that venv will used the python exe installed in that virtual environment and use the packages you just installed there
I need to install a certain package, for which the developers suggest Python 3.5, since they don't support 3.7 yet.
I am running Mac OS Mojave 10.14.2 and my Python version is 3.7.1.
I have come across methods to switch between Python 2.x and 3.x using Virtualenv, such as below:
virtualenv -p python2 myenv
virtualenv -p python3 myenv
However, is it even possible to have a specific version of Python, that too one older than I have already installed on my system?
Yes, it is possible to have multiple versions of Python installed on OSX. Each one installs to a different path. You can't have multiple 'python3' executables in your path -- but if you use the absolute path then it'll work out fine.
You can go download the OSX version of Python 3.5 (which will install itself as python3.5 somewhere), and then create a virtualenv via
virtualenv -p /absolute/path/to/python3.5 myenv
you can use
python -m virtualenv <env_name> --python=<full-path-to-python-exectuable-file-and-exe-file>
here <full-path-to-python-exectuable-file-and-exe-file> add python3.5 which you have downloaded
I am trying to start a Python 3.6 project by creating a virtualenv to keep the dependencies. I currently have both Python 2.7 and 3.6 installed on my machine, as I have been coding in 2.7 up until now and I wish to try out 3.6. I am running into a problem with the different versions of Python not detecting modules I am installing inside the virtualenv.
For example, I create a virtualenv with the command: virtualenv venv
I then activate the virtualenv and install Django with the command: pip install django
My problems arise when I activate either Python 2.7 or 3.6 with the commands
py -2 or py -3, neither of the interactive shells detect Django as being installed.
Django is only detected when I run the python command, which defaults to 2.7 when I want to use 3.6. Does anyone know a possible fix for this so I can get my virtualenv working correctly? Thanks! If it matters at all I am on a machine running Windows 7.
Create virtual environment based on python3.6
virtualenv -p python3.6 env36
Activate it:
source env36/bin/activate
Then the venv36 has been activated, venv36's pip is available now , you can install Django as usual, and the package would be stored under env36/lib/python3.6/site-packages:
pip install django
You have to select the interpreter when you create the virtualenv.
virtualenv --python=PYTHON36_EXE my_venv
Substitute the path to your Python 3.6 installation in place of PYTHON36_EXE. Then after you've activated, python executable will be bound to 3.6 and you can just pip install Django as usual.
The key is that pip installs things for a specific version of Python, and to a very specific location. Basically, the pip command in your virtual environment is set up specifically for the interpreter that your virtual environment is using. So even if you explicitly call another interpreter with that environment activated, it will not pick up the packages pip installed for the default interpreter.
I have two versions of python on Mac OSX Yosemite, 2.7 and 3.5 and I have a virtual environment to switch the workspace to 3.5 version.
I switched the environment to python 3.5 and then install the selenium webdriver package using "sudo pip install selenium". It gets installed without any issues but then I tried to uninstall it and then noticed that it is asking for confirmation and then I noticed that the path was shown for python 2.7 version.
The paths are for python 2.7, why did the package got installed in 2.7 instead of 3.5 even though I was in a virtual environment of 3.5 version?
You could use pip3 instead of pip so you are sure that the 'pip' you are calling is the one related to python3.
pip3 install selenium
This often happens when you use pip with sudo. That is because the environmental variables created by the activate script in the virtualenvare often valid only for the current user and not for the super user. You can confirm this by typing these two commands after activating the virtualenv.
which python
sudo which python
You will see that the latter points to the system python installation.
One solution is to create the virtualenv in the userspace so that you don't need superuser privileges to make changes to it. The other is to do sudo -i, activate the virtualenv and then do the pip install.
I am running Windows x64 bit.
I downloaded the Pyro4 package via pip install Pyro4. It downloaded the packages successfully and they are all present in my "C:\Python34\Scripts" folder as I've kept Python3.4 as default.
Now when I went to the that "C:\Python27\Scripts" folder, the Pyro4 package is not to be found. This is as expected, but I would like to work on both Python 2.7 and 3.4 as Pyro4 is compatible in both.
How do I change my pip command to download the package to Python 2.7's installation scripts directory?
First make a new environment variable:
Go to your system properties
Under Advanced tab click Environment Variables...
Under System variables section click New...
Variable name: (whatever you can remember for example p27s)
Variable value: your python 2.7 scripts folder ("C:\Python27\Scripts\")
From now on whenever you want to install a package for python 2.7 you can do it this way: %your_variable_name%pip install package_name
For example: C:>%p27s%pip install Pyro4
This way you can install any package for python 2.7 and use default pip for python 3.4
You will need to go to your environment variables in the control panel and change the path from C:\Python34\Scripts to C:\Python27\Scripts. After that change, when you type 'python' in the command prompt it will be using Python 2.7. Next, install pip like you initially did.
Not exactly what you're asking, but you could check out Anaconda which allows you switch python environments really easily.
https://www.continuum.io/downloads
Edit
Just to clarify
if you were to use this method, you can have named environments say python27 and python34
then you can just:
activate python27
pip install module
activate python34
pip install module
and it will install them to both environments.