Skip to content

Instantly share code, notes, and snippets.

@jlesquembre
Created March 15, 2012 08:12
Show Gist options
  • Save jlesquembre/2042882 to your computer and use it in GitHub Desktop.
Save jlesquembre/2042882 to your computer and use it in GitHub Desktop.
Creates a symlink to PyQt libraries when a new virtual environment is created
#!/bin/bash
# This hook is run after a new virtualenv is activated.
# ~/.virtualenvs/postmkvirtualenv
libs=( PyQt4 sip.so )
python_version=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
var=( $(which -a $python_version) )
get_python_lib_cmd="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
lib_virtualenv_path=$(python -c "$get_python_lib_cmd")
lib_system_path=$(${var[-1]} -c "$get_python_lib_cmd")
for lib in ${libs[@]}
do
ln -s $lib_system_path/$lib $lib_virtualenv_path/$lib
done
@nerdoc
Copy link

nerdoc commented Jan 17, 2014

Under Ubuntu (13.10), this links to /usr/lib/python3.3/site-packages/sip.so and /usr/lib/python3.3/site-packages/PyQt4, which are non-existent. These files are living in /usr/lib/python3/dist-packages/
This is because Debian/Ubuntu installs Python packages into dist-packages, not site-packages.
So the script is not usable under *buntu/Debian

@bootchk
Copy link

bootchk commented May 12, 2014

Yes, but it is useable if you build PyQt yourself, since it installs to site-packages. But then, python3 on Ubuntu/Debian does not seem to have site-packages in its PYTHONPATH.

So is there a general problem, that Debian has broken a Python convention that the default PYTHONPATH includes site-packages? Is that the mess that virtualenv is designed to fix?

@Freizello
Copy link

Thanks! it works with a little change on sip.so to sip.x86_64-linux-gnu.so in my ubuntu 16.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment