Pipenv vs setup.py

Viewed 18816

I am trying to migrate 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 stuff like from myproject.xyz.abc import myClass from anywhere within the project.

How do I achieve the similar effect with pipenv and get rid of the setup.py?

Note: I am using python 2.7.

3 Answers

Update:

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

Original answer:

pipenv install -e is buggy and has been fixed in master (pull request). It will be available in the next release, sometime after Thanksgiving.

Temporary workaround for now is:

pipenv shell
pip install -e .

After the release, you should be able to run pipenv install -e . similar to what you'd expect with pip.

In your case, pipenv replaces pip but you will still need a setup.py.

Assuming your directory is structured like this:

dir_a/              <-- This will be your pipenv root dir and your package root dir.
    setup.py
    dir_b/
        __init__.py
        somefile.py
        otherfile.py

Then you can initiate a Python 3 environment and install your package using:

$> cd dir_a
$> pipenv --python 3
$> pipenv shell
$> pipenv install -e . 

You can verify that the package has been installed using cat Pipfile or pipenv graph.

However, if your package root directory is not the same as your pipenv root directory then pipenv install -e . will fail with a mysterious error message:

Error parsing requirement . -- are you sure it is installable?

In this case, you should call pipenv install -e from the pipenv root directory and give the path to the root directory of the package. For example, with this file structure:

dir_z/              <-- This will be your pipenv root dir.
    something.py
    empty_dir/
    dir_a/          <-- This is your package root dir.
        setup.py
        dir_b/
            __init__.py
            somefile.py
            otherfile.py

You would use:

$> cd dir_z
$> pipenv --python 3
$> pipenv shell
$> pipenv install -e dir_a/

As another user mentioned, using pip install -e . does install the package into the virtual environment from dir_a in this scenario. However, at least for me, it doesn't update the Pipfile so is not of much use.

Related