I created a new local virtualenv version of python and did the following to see what copy of json was being run. For some reason the version that's being run is not the newly created virtualenv version. Can someone explain this? I would expect that my virtualenv would be a brand new copy that has NOTHING to do with the system-wide copy, especially since I ran it with the --no-site-packages flag.
(TEST) GBMAC0122 ~/Desktop/test $ virtualenv . --no-site-packages
New python executable in /Users/jonathan/Desktop/test/bin/python
Installing setuptools, pip, wheel...done.
(TEST) GBMAC0122 ~/Desktop/test $ source bin/activate
(test) GBMAC0122 ~/Desktop/test $ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.pyc'
--no-site-packages (which is now the default behavior) instructs virtualenv to give each new environment a fresh site-packages, which is where new modules are installed. There's no point in copying builtin modules like json because regardless of the environment you're in, builtin modules are assumed to be untouched. You shouldn't be changing them to begin with.
Interestingly, virtualenv does have to copy a few builtin modules to make the site module work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With