makefile in virtualenv is compiling to wrong python version - python

My machine is running python 2.6, with a virtual environment running 2.7.
I enter the virtualenv and run configure, make, then make install to build an application (pyqt4 FWIW).
My problem: when I compile the application, its done with python 2.6.
How can I tell it to use the version of the virtual environment (2.7).
I have confirmed the virtual environment does indeed have 2.7 and I have set the python alias to python2.7, but no joy.

virtualenv only provides the environment for python, easy_install and pip, but not make. you could run the following to verify:
which make
According to instruction here, I guess you need to run the following command:
python configure-ng.py
which should trigger the correct python in virtualenv.

Related

how should i be using python 3.6 and python 3.7 side by side on msys2 and cmder?

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

Local python 3.6?

(I'm new to Python and venv, so please bear with me)
I have a Python application that needs Python 3.6 (or later) and many libraries.
I've already used venv to create a requirements.txt that specifies all the libraries I need. I've successfully installed and run my app on a new machine with Python 3.6.
Now, I need to run it on a machine where I do not have root access, and where Python 3.5.5 is installed. What are the steps to install a local copy of a more recent Python and have it be used in my venv?
First of all, if you want to create a Python 3.6 venv, the host machine must have Python 3.6 installed.
You can't have a virtual environment of Python 3.6 if the 3.6 is not installed on system. But if you have an already created venv in 3.6, you can very well move it to target machine. Both servers must have same OS.
If your target machine OS is different, then you have to install python 3.6 to your home directory, check here for installantion instructions (basicly you will use ./configure prefix=/home/david/python3.6 while installing).
After installing python 3.6, use -p flag for venv to point your python executable like this: venv -p /home/david/python3.6/bin/python

awscli running with python 2.7 on OS x Sierra

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.

Virtualenv installing modules with multiple Python versions

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.

Virtualenv gives different versions for different os

I am working on a django project on two separate systems, Debian Jessie and Mac El Capitan. The project is hosted on github where both systems will pull from or push to.
However, I noticed that on my Debian, when I run python --version, it gives me Python 3.4.2 but on my Mac, it gives me Python 2.7.10 despite being in the same virtual environment. Moreover, when I run django-admin --version on my Debian, it gives me 1.10 while on my Mac, 1.8.3.
This happens even when I freshly clone the projects from github and run the commands.
Why is it that the virtual environment does not keep the same version of python and django?
Now you understand that virtual environments can't be transferred easily from machine to machine. It's common to use the
pip freeze
command and store its output in a file called requirements.txt. Then anyone else can rebuild your envirnment on their machine by running
pip install -r requirements.txt
When you create a new virtual environment you can say which Python interpreter you want to use with the -p or --python switch, which should be followed by the path to the correct executable.
I'd personally recommend against modifying the system Python in any way, because system maintenance routines often rely on its integrity. It's relatively simple to install new copies for Python 2 and 3 somewhere like /usr/local/bin (Mac users often use brew for this) and have virtual environments that rely on different Python interpreters.
Thanks to #Oliver and #Daniel's comments that lead me to the answer why it did not work.
I started the virtual environment on my Debian with python 3. virtualenv made the virtual environment but it was specifically for Debian.
When I used it for mac, since it could not run the python executable in the virtual environment (since it is only compatible with Debian), hence, it used my Mac's system python, which is Python 2.7.10.
In summary, as virtualenv uses the python executable on the system, when the python executable is run on another system, it will not work.

Categories

Resources