Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipenv: dependencies of platform specific packages are installed unconditionally?

Tags:

python

pipenv

I am trying to integrate pipenv into my new project because I need to have some dependencies for development only and I couldn't find an easy way to have additional dev dependencies with pip or venv.

However, I ran into an issue when trying it:

My project depends on pypiwin32 when it's used in windows. Because it's a windows dependency, I installed it with the command:

pipenv install "pypiwin32 ; platform_system == 'Windows'"

which succesfully added this dependency to my Pipfile with the platform restriction:

# Pipfile

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
# dependencies...

[packages]
# dependencies...
pypiwin32 = {markers = "platform_system == 'Windows'",version = "*"}

[requires]
python_version = "3.7"

The problem is that pypiwin32 depends on the pywin32 package and when I looked in the Pipfile.lock file I saw that it's not restricted to windows only:

# Pipfile.lock

"pypiwin32": {
    "index": "pypi",
    "markers": "platform_system == 'Windows'",
    "version": "==223"
},
"pywin32": {
    "version": "==224"
},

which is weird. I tested it by changing the restriction to 'Linux' and trying to install the dependencies into a new environment without the Pipfile.lock and it ignored pypiwin32 as expected but it installed pywin32 anyway despite the fact that it's not listed in the Pipfile and that it's a dependency of a package which was ignored.

This is a serious problem because if I decide to deploy or develop on a linux machine, it will simply not work because pywin32 isn't available on linux or mac (as far as I know).

Is there a way to correctly mark the dependencies of a package with the restrictions of the package?

I don't want to manually edit Pipfile.lock (I also don't think it will work because when I tried to install it into a new environment, I copied the Pipfile only).

Alternatively, is there a better way to manage my dependencies? I need the ability to specify development dependencies that won't be installed on a production environment and I need the ability to specify platform specific dependencies. pip with the requirements.txt can't handle the first request as far as I know, which is why I tried switching to pipenv.

I tried looking it up with no success. Any help would be appreciated.

like image 542
Shai Avr Avatar asked Aug 01 '19 18:08

Shai Avr


1 Answers

Adding platform specific installation of both pypiwin32 and pywin32 packages explicitly in the pipfile should solve the issue.

pypiwin32 = {version = "*", sys_platform = "== 'win32'"}
pywin32 = {version = "*", sys_platform = "== 'win32'"}

The prerequisite package pywin32 will in that case also be ignored on linux.

like image 50
Jietse Van Thienen Avatar answered Oct 24 '22 17:10

Jietse Van Thienen