WebFaction
Community site: login faq

I am using Python 3.5 and pyvenv instead of virtualenv for the first time, and have run into a spot of trouble. I have, for instance, run these commands to set up my venv:

$ pyvenv-3.5 my_venv $ source my_venv/bin/activate (my_venv) $

My understanding is, according to the python docs, that pyvenv, by default, has the include-system-site-packages key set to false in its configuration file. However, not having installed Django in my venv at all, I can run this:

(my_venv) $ django-admin.py --version 1.6.5

...and see the system-wide Django version, which I shouldn't be able to.

According to this older question, there is a global site customization policy in WebFaction's system Python installations, which virtualenv was unable to ignore. The solution was to create an empty file named sitecustomize.py in your environment's lib/pythonx.x directory. That does not seem to work under the pyvenv environment, so I'm wondering what the correct way to fully encapsulate the environment is here.

asked 26 Jun '16, 02:12

bobtiki's gravatar image

bobtiki
155
accept rate: 100%

1

What the virtualenv is seeing is not the system-site-packages. Rather, it's seeing packages which are added in sitecustomize.py and generally adding the empty sitecustomize.py under the environment's lib/python3.5 directory would solve the problem.

Therefore, I'm unsure why that's not working in this case here. If you enter which django-admin.py, which one is on the PATH? Also, if you enter a python3.5 python prompt and import django and then print(repr(django)), which one was imported? What is sys.path in that case?

(26 Jun '16, 03:04) ryans ♦♦ ryans's gravatar image

RyanS, I did what you asked, and I admit I'm a bit confused now. Here's the whole Terminal sequence:

$ pyvenv-3.5 my_venv
$ source my_venv/bin/activate
(my_venv) $ touch my_venv/lib/python3.5/sitecustomize.py
(my_venv) $ django-admin.py --version
1.6.5
(my_venv) $ which django-admin.py
~/bin/django-admin.py
(my_venv) $ python3.5
Python 3.5.1 (default, Jan 23 2016, 01:36:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
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'
>>> import sys
>>> print(sys.path)
['', '/usr/local/lib/python35.zip', '/usr/local/lib/python3.5', '/usr/local/lib/python3.5/plat-linux', '/usr/local/lib/python3.5/lib-dynload', '/home/bobtiki/webapps/bobtiki_cms/my_venv/lib/python3.5/site-packages']

(Edited because apparently triple-ticks don't demarcate code blocks in comments. :P )

(26 Jun '16, 17:21) bobtiki bobtiki's gravatar image

After further investigation, it looks like when I add the empty sitecustomize.py under the environment's lib/python3.5 directory, that it does actually provide the fix I need to restrict what my Python app actually sees. I'm guessing there's something in my system PATH that's otherwise showing me things at the command line that I thought I shouldn't be seeing, but it doesn't really matter once I'm running Python. Thanks, RyanS!

permanent link

answered 27 Jun '16, 18:35

bobtiki's gravatar image

bobtiki
155
accept rate: 100%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×48
×21
×5

question asked: 26 Jun '16, 02:12

question was seen: 731 times

last updated: 27 Jun '16, 18:35

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM