Virtualenv on Ubuntu with no site-packages
I've been using virtualenv lately while developing in python. I like the idea of a segregated development environment using the --no-site-packages option, but doing this while developing a PyGTK app can be a bit tricky. The PyGTK modules are installed on Ubuntu by default, and I would like to make a virtualenv (with --no-site-packages) aware of specific modules that are located elsewhere on the system.
What's the best way to do this? Or should I just suck it up and drop the --no-site-packages option?
Asked by: Edgar556 | Posted: 28-01-2022
Answer 1
$ virtualenv --no-site-packages --python=/usr/bin/python2.6 myvirtualenv
$ cd myvirtualenv
$ source bin/activate
$ cd lib/python2.6/
$ ln -s /usr/lib/pymodules/python2.6/gtk-2.0/
$ ln -s /usr/lib/pymodules/python2.6/pygtk.pth
$ ln -s /usr/lib/pymodules/python2.6/pygtk.py
$ ln -s /usr/lib/pymodules/python2.6/cairo/
$ python
>>> import pygtk
>>> import gtk
Answered by: Carlos550 | Posted: 01-03-2022
Answer 2
One way is to add the paths to your code using sys.path.
import sys
sys.path.append(somepath)
Another way is to use site, which processes .pth files in addition to adding to sys.path.
import site
site.addsitedir(sitedir, known_paths=None)
https://docs.python.org/library/site.html
But you probably don't want to add this to all your related code.
I've seen mention of sitecustomize.py being used to perform something like this, but after some testing I couldn't get it to work as might be expected.
Here it mentions that auto-import of sitecustomize.py ended in 2.5, if your not on 2.5 try it out. (just add one of the path add methods above to the file and drop it in the directory your program is run) A work around method is mentioned in the post for users of 2.5 and up.
http://code.activestate.com/recipes/552729/
Answered by: Audrey916 | Posted: 01-03-2022Answer 3
I find in this situation, symlinks, or even copying specific files (packages, modules, extensions) works really well.
It allows the program to emulate being run in the target environment, rather than changing the application to suit the development environment.
Same deal for something like AppEngine.
Answered by: Cadie151 | Posted: 01-03-2022Answer 4
Check out the postmkvirtualenv hook script here:
https://stackoverflow.com/a/9716100/60247
In that case, he's using it to import PyQt and SIP after a new Virtualenv is created, but you can add the packages that you need to LIBS.
And vote that script up because it's fantastic :)
Answered by: Catherine649 | Posted: 01-03-2022Answer 5
If you want to include the links to the relevant system's python gtk-2.0 in the virtualenv, you can just use pip to install ruamel.venvgtk:
pip install ruamel.venvgtk You don't have import anything, the links are setup during installation.
This is especially handy if you are using tox
, in that case you only need to include the dependency (for tox):
deps:
pytest
ruamel.venvgtk
and a newly setup python2.7 environment will have the relevant links included before the tests are run.
More detailed information on how the links are setup can be found in this answer
Answered by: Andrew713 | Posted: 01-03-2022Similar questions
python - Cannot select the proper site-packages folder using virtualenv
I see a lot of help on the internet about finding out where the site-packages that you're using is located but not information about how to fix the problem if you're using an undesirable site-package folder. I'm using virtualenv and I would think that if I input in command line:
cd /users/me/documents/codes/venv3/bin && source activate && cd /users/me/documents/pcode/
that I...
python - virtualenv, sys.path and site-packages
i am setting up a virtualenv for django deployment. i want an isolated env without access to the global site-packages. i used the option --no-site-packages, then installed a local pip instance for that env.
after using pip and a requirements.txt file i noticed that most packages were installed in a "build" folder that is not in sys.path so i am getting an error such as
"no module named django.conf"
...
python - Macports and virtualenv site-packages Fallback
I've installed django and python as this link suggested with macports. However, I'd like to use virtualenv to install more packages. My understanding is that if I do not pass in the --no-site-packages to virtualenv, I should get the currently installed packages in addition to what...
python - Linux Fedora virtualenv site-packages incorrect location
I have just tried to set install an application in my new virtual environment.
To create my virtual environment I used:
virtualenv -p /usr/bin/python2.6/python2.6 rollEnv2 --no-site-packages
Then to install the application, I used:
python setup.py install
But I get an error at the end:
File "/home/aaron/workspace/rollEnv2/lib/python...
python - Modifying a virtualenv so that packages installed in global site-packages are available
This question already has answers here:
python - Pip recognize linked site-packages in virtualenv
For a number of reasons, such as when the package takes a long time to compile (lxml) it seems to be recommended to symlink such packages from the system sitepackages directory to a virtualenv.
Some example questions:
Use a single site package (as exception) for a virtualenv
How to install ...
python - Convert to virtualenv an existing project by copying site-packages
I have an old Django project that I want to convert to use virtualenv. If I could copy the current global Python packages to the new env, I think I'd be assured that I'd have the same environment and would save myself some time over creating a requirements file by hand. So, could I just copy the global site-packages contents into the env's site-packages directory?
python - make some modules from global site-packages available in virtualenv
I want to use the default (no site packages) of virtualenv.
But some modules are difficult to install in a virtualenv (for example gtk). With "difficult" I mean that you need to have a lot of c-header files installed and a lot of stuff needs to be compiled.
I know that I can solve this by not installing these packages with pip, but to create symlinks to make some modules available from the global site-pack...
python - Site-Packages in Python2.7 without VirtualEnv
When I use pip install matplotlib --upgrade it runs and installs matplotlib and all dependicies, and at the end reads uninstalled version '1.3.1'. Running python and matplotlib.__version__ outputs '1.3.1' again, even though it was just declared uninstalled. How do I switch which python I'm running from, which would hopefully be where pip is insta...
python - LiClipse and virtualenv - LiClipse does not know modules from site-packages
So I just created a new virtual environment and linked it to a project in LiClipse by setting the interpreter as standard interpreter for the project. The only problem is, that packages installed to the site-packages folder by pip don't seem to be recognized by LiClipse. Is there a step I might have forgotten? I followed this tutorial
python - Switched from virtualenv uwsgi to global uwsgi and site-packages seems not to be found
I followed this guide: https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
Switching from a virtualenv uwsgi install to a global uwsgi produces this error:
Traceback (most recent call last):
File "/var/MyServer/lib/python3.4/site-packages/django/__init__...
python - Eclipse PyDev: setting breakpoints in site-packages source
I am debugging a problem in Django with Pydev.
I can set breakpoint in my django project code with out a problem.
However I can't set breakpoints in the Django library source code (in site-packages).
The PyDev debugger user interface in this case simply does nothing when I click to set the breakpoint and ...
ubuntu - ubuntu9.10 : how to use python's lib-dynload and site-packages directories?
In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0
Only python 2.6 is actually working.
python2.4 has only a lib-dynload directory,
python2.5 has only lib-dynload and site-packages,
python3.0 has only a dist-packages directory.
Now i'm wondering what is the idea behind this?
Because when i install python2.5 with ./configure, make, make install...
python - Virtualenv: global site-packages vs the site-packages in the virtual environment
If I have a certain package installed both in the global site-packages and in the local one, which package will get imported? Will that even work or will I get an error?
Which packages should I put in the global site-packages and which in the local one?
Vim - run ctags on current python site-packages
This is what I need - have a key that will create ctags of my python site-packages.
I have this command, that will print the site-packages path:
!python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
This is how I to the key mapping:
map <F11> :!ctags -R -f ./tags *site-packages-path-goes-here*<CR>
How do I ...
macos - How can I replace a Python 2.65 UCS-2 build with one built using UCS-4 without losing everything in my site-packages?
I downloaded the Python 2.6.5 source, built it for OS 10.6.4 64-bit, and installed numerous dependencies. I opened a big project our team has been working on recently, ran the unit tests, and one of the tests failed because I had installed Python built using UCS-2 (I didn't know this was the default of OS X!)
In a nutshell:
I didn't supply flag --enable-unicode=ucs4 when building Pytho...
python - virtualenv, sys.path and site-packages
i am setting up a virtualenv for django deployment. i want an isolated env without access to the global site-packages. i used the option --no-site-packages, then installed a local pip instance for that env.
after using pip and a requirements.txt file i noticed that most packages were installed in a "build" folder that is not in sys.path so i am getting an error such as
"no module named django.conf"
...
python - Macports and virtualenv site-packages Fallback
I've installed django and python as this link suggested with macports. However, I'd like to use virtualenv to install more packages. My understanding is that if I do not pass in the --no-site-packages to virtualenv, I should get the currently installed packages in addition to what...
python - Can't figure out how to include *.html files within a site-packages folder
I cannot figure out how to write my setup.py script in order to include *.html files within the installed package.
Here is my attempt:
import os
from setuptools import setup, find_packages
setup(name='django-testapp',
version='0.1',
author='RadiantHex',
license='BSD',
keywords='testapp,django',
packages=['testapp']],
include_package_data=True,
data_files = os.walk('testapp'),
zip_sa...
python - Installing modules into a custom site-packages directory
I have inherited a half-finished django project
which uses a custom site-packages directory that
is checked into subversion along with the code.
Being a newbie to python, I'm wondering if I can just
copy the contents of some eggs - that I want to add
into the django project - directly into this
site-packages directory from my ubuntu dist-packages directory.
/u...
macos - Mac Python pointing to different site-packages after python upgrade - How do i point all site-packages to correct python version?
I am trying to upgrade my Mac from 2.6 to 2.7 and everything went fine except for some libraries are being used from 2.6 now instead of 2.7, any idea how I can point all the new libraries to 2.7? Basically I am trying to install yolk for 2.7 but it says that its already installed (under 2.6).
$ python
Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", ...
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python