Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip installs headers in virtualenv to a directory not included by default in build_ext #4610

Closed
segevfiner opened this issue Jul 8, 2017 · 4 comments
Labels
auto-locked Outdated issues that have been locked by automation state: needs discussion This needs some more discussion

Comments

@segevfiner
Copy link
Contributor

segevfiner commented Jul 8, 2017

  • Pip version: 9.0.1
  • Python version: 2.7.13
  • Operating system: Windows 10.0.15063 x64

Description:

When installing a package in a virtualenv, it's headers get installed to a different directory than plain distutils, which is not included by default in the build_ext include directories. Such headers won't be found by packages that depend on it unless the package takes special care to calculate the directory used by pip and adding it manually to it's Extensions in setup.py.

For example, on Windows:

What I've run:

# setup.py
from setuptools import setup

setup(
    name="spam",
    version="0.1.0",
    headers=["include/spam/spam.h"],
)

Then:

virtualenv venv
venv\Scripts\activate
pip install .

Workaround

import sys
import os
import sysconfig
from setuptools import setup, Extension

include_dirs = []

venv_include_dir = os.path.join(sys.prefix, 'include', 'site', 'python' + sysconfig.get_python_version())
if os.path.exists(venv_include_dir):
    include_dirs.append(venv_include_dir)

setup(
    name="ham",
    version="0.1.0",
    ext_modules=[
        Extension("ham", ["ham.c"], include_dirs=include_dirs),
    ],
)
@pradyunsg
Copy link
Member

@pfmoore This is an compilation on Windows issue. I think you'd have more idea about this than me here.

@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label May 10, 2018
@pfmoore
Copy link
Member

pfmoore commented May 10, 2018

The details of how Python sets and uses the sysconfig include directory are not something I know much about. You'd probably need one of the scientific Python people (who have plenty of battle scars from dealing with this stuff) to get a good answer here.

Some random thoughts:

  1. pip install . is doing a source install, so it'll be setuptools that chooses where to install the headers, not pip.
  2. For wheels, move_wheel_files puts the distribution-1.0.data/headers directory into the location defined by scheme["headers"]. This should come from sysconfig.
  3. setuptools.Extension determines where to tell the compiler to look for headers, and it should be working that out from the scheme.

So, my suspicion is that any inconsistency is a result of the various components not agreeing on what scheme should be used, and/or the whole sysconfig scheme mechanism not being well defined for virtual environments (and the tools differing in how they choose to extend the mechanism to handle virtual environments).

So, in summary, the root of this is probably a limitation of the sysconfig mechanisms not covering virtual environments. That's a core Python issue ultimately. At the moment, there's an inconsistency in how the various tools extend the schemes to virtual environments, and we should probably make that more consistent (and standardise it maybe). Given that changing core Python is a long-term thing, agreeing a standard for tools to follow is a better short term approach (and the stdlib can catch up later).

But once again, I have little actual experience in this area - if the numeric guys say something different, they are right and I'm wrong 😄

@chrahunt
Copy link
Member

Related to pypa/packaging-problems#84.

Is there anything directly actionable for pip here or would it be better to continue in a discuss.python.org topic or the issue above?

@chrahunt chrahunt added the state: needs discussion This needs some more discussion label Aug 10, 2019
@triage-new-issues triage-new-issues bot removed the S: needs triage Issues/PRs that need to be triaged label Aug 10, 2019
@chrahunt
Copy link
Member

One strategy, as discussed in #7455 and here, is to inspect the installed packages/sys.path and determine the paths from that in your setup.py. I'll close this issue with the same conclusion. As mentioned over there, don't hesitate to post if you come up with something!

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jan 11, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation state: needs discussion This needs some more discussion
Projects
None yet
Development

No branches or pull requests

4 participants