Skip to content

Instantly share code, notes, and snippets.

@k4ml
Created November 15, 2012 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save k4ml/4080461 to your computer and use it in GitHub Desktop.
Save k4ml/4080461 to your computer and use it in GitHub Desktop.
Copy system packages into virtualenv
import os
import sys
import shutil
pkgname = sys.argv[1]
venv = sys.argv[2]
pyversion = '%s.%s' % (sys.version_info[0], sys.version_info[1])
try:
pkgobj = __import__(pkgname)
except Exception as e:
print e
sys.exit(1)
pkgdir = os.path.dirname(pkgobj.__file__)
dst = '%s/lib/python%s/site-packages/%s' % (venv, pyversion, pkgname)
shutil.copytree(pkgdir, dst)
@AGI-chandler
Copy link

Could you please update for python 3.11?  When I try to run:

$ python3 ~/.local/src/k4ml/syspkg.py pkg ~/.venv/pkg
  File "/home/chandles/.local/src/k4ml/syspkg.py", line 12
    print e
    ^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
$ 

If I change to print(e) then it runs without error but doesn't seem to do anything either as nothing new is put into ~/.venv/pkg.
Thanks

@k4ml
Copy link
Author

k4ml commented Feb 5, 2023

It should work. The library will be copied to .venv/lib/python3.XX/site-packages/, not .venv/.

@AGI-chandler
Copy link

Got it!  Thanks!  Sorry...

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