Pipenv vs. setup.py

I am trying to upgrade to pipenv . I traditionally used setup.py with pip and did pip install -e . to install the module as a package so that I can achieve things like from myproject.xyz.abc import myClass from anywhere in the project.

How to achieve a similar effect using pipenv and get rid of setup.py ?

Note. I am using python 2.7 .

+7
python pip setuptools pipenv
source share
2 answers

Update:

pipenv 9.0.0 has been released , which should allow you to use pipenv install -e . , as was expected.

Original answer:

pipenv install -e is a bug and fixed in the main ( pull request ). It will be available in the next issue, sometime after Thanksgiving.

A temporary workaround for now:

 pipenv shell pip install -e . 

After the release, you can run pipenv install -e . similar to what you expect with pip .

+9
source share

If you run pipenv install -e . in a package that does not have setup.py, you will get:

 $ pipenv install -e . Directory '.' is not installable. File 'setup.py' not found. 

So you need setup.py anyway for such a case.

It is important to understand the concept of applications and packages. This information may be useful https://caremad.io/posts/2013/07/setup-vs-requirement/

If you are building an application, pipenv is the only thing you need.

However, if you are creating a package, then you must have setup.py in any case to allow its installation or installation (possibly in editable mode).

pipenv 's pipenv is here: https://github.com/pypa/pipenv/issues/1161#issuecomment-349972287

So pipenv vs setup.py is the wrong wording. They cannot be against each other. Rather support each other or exclude each other.

We may need to find a way to use both of them without duplication.

When you create the package, you can still use pipenv, but this leads to duplication of things (requiremets in setup.py and Pipfile). To do this, I use the following approach:

 import pathlib import subprocess from setuptools import setup, find_packages from setuptools.command.install import install from setuptools.command.develop import develop __requires__ = ['pipenv'] packages = find_packages(exclude=['tests']) base_dir = pathlib.Path(__file__).parent pipenv_command = ['pipenv', 'install', '--deploy', '--system'] pipenv_command_dev = ['pipenv', 'install', '--dev', '--deploy', '--system'] class PostDevelopCommand(develop): """Post-installation for development mode.""" def run(self): subprocess.check_call(pipenv_command_dev) develop.run(self) class PostInstallCommand(install): """Post-installation for installation mode.""" def run(self): subprocess.check_call(pipenv_command) install.run(self) with open(base_dir / 'README.md', encoding='utf-8') as f: long_description = f.read() setup( name='dll_api', use_scm_version = True, long_description='\n' + long_description, packages=packages, setup_requires=['setuptools_scm'], cmdclass={ 'develop': PostDevelopCommand, 'install': PostInstallCommand, }, ) 

Now you have the following:

 $ python setup.py install running install Installing dependencies from Pipfile.lock (e05404)… 

Note pipenv must be installed before!

This is not an easy way to solve the problem, however, do the job.

+4
source share

All Articles