I am tasked with setting up a Django environment on a RHEL 7 virtual machine. (I am from a Windows background so this is a challenge.) I installed Python 2.7.13 32-bit and pip alongside the default 2.7.5 64-bit, as per this tutorial https://tecadmin.net/install-python-2-7-on-centos-rhel/.
This seems fine - I can access 2.7.5 using python
and 2.7.13 using python2.7
I then created a virtual environment sudo virtualenv -p /usr/local/bin/python2.7 venv
pointing at 2.7.13, with the following output...
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in /home/butterp/venv/bin/python2.7
Also creating executable in /home/butterp/venv/bin/python
Installing setuptools, pip, wheel...done.
Now, after activating the venv, python
or python2.7
initiates the 2.7.13 interpreter, which is what I want.
I merrily installed my requirements using sudo pip
, as I get permission errors without sudo
, which seemed to go well. However, the packages are not available when I try to import them in Python
(venv) [butterp@dev ~]$ python
Python 2.7.13 (default, Sep 8 2017, 03:33:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
The packages were installed to the base install of python2.7 /usr/lib/python2.7/site-packages rather than the venv, and I CAN import them if I use sudo python
or sudo python2.7
, although both commands take me to version 2.7.5!
[butterp@dev ~]$ sudo python
Python 2.7.5 (default, May 3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
It looks like an error stemming from my misuse of sudo
and/or pip
, but I am stuck at Confusion Central and unsure how to rectify the situation. Can anyone help? Cheers!