Is possible to add a python path with pipenv?

1.8k Views Asked by At

I have some old python projects that are NOT packaged (no setup.py) I need to access them. Till now I was using buildout where I can specify a python path in buildout.cfg. I would like to switch to pipenv : how can I specify an arbitrary python path with pipenv so I can import my unpackaged projects ?

1

There are 1 best solutions below

0
Eric On

I finally wrote a script that creates a .pth file with all the pythonpath I wanted to add in the virtualenv:

#!/usr/bin/env python
from distutils import sysconfig
import os
site_packages_path = sysconfig.get_python_lib()

PTH_FILENAME = 'MyApp.pth'
# Change here to your project home dir
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

relative_paths = [
  '.',
  'plugins',
  'src/achilterm',
  'src/addicted',
  'src/naghelp',
  'src/textops',
  'src',
]

absolute_paths = [ os.path.join(PROJECT_DIR,p) for p in relative_paths ]

with open(os.path.join(site_packages_path,PTH_FILENAME),'w') as fh:
    for p in absolute_paths:
        print 'Installing path : %s ...' % p
        fh.write('%s\n' % p)