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 ignore the Python -I flag in build env #13023

Closed
1 task done
bebound opened this issue Oct 17, 2024 · 2 comments
Closed
1 task done

pip ignore the Python -I flag in build env #13023

bebound opened this issue Oct 17, 2024 · 2 comments
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior

Comments

@bebound
Copy link

bebound commented Oct 17, 2024

Description

When I use python -Im pip, the -I is not passed to build env, and the unwanted sys.path is not exclude. I'm not sure whether this is the expected behavior, because I know some pip args also not passed to build env as mentioned in #9081.

I encountered a rare case where the pipeline agent has Python 3.12.6 installed, and I'm trying to use embedded Python 3.12.7. There seems to be a compatibility issue between versions 3.12.6 and 3.12.7; running python.exe -m pip fails with return code 50075, but python.exe -Im pip works fine. However, in the build env, since -I is not passed, when use pep517 build, pip fails with 57005.

I wonder if this possible to honor this isolated flag in build env.

./python.exe -m site 
sys.path = [
    'D:\\a\\_work\\1\\s\\artifacts\\Python',
    'D:\\a\\_work\\1\\s\\artifacts\\Python\\python312.zip',
    'C:\\hostedtoolcache\\windows\\Python\\3.12.6\\x64\\Lib',
    'C:\\hostedtoolcache\\windows\\Python\\3.12.6\\x64\\DLLs',
    'D:\\a\\_work\\1\\s\\artifacts\\Python\\Lib',
    'D:\\a\\_work\\1\\s\\artifacts\\Python\\Lib\\site-packages',
]
USER_BASE: 'C:\\Users\\cloudtest\\AppData\\Roaming\\Python' (doesn't exist)
USER_SITE: 'C:\\Users\\cloudtest\\AppData\\Roaming\\Python\\Python312\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True
Using pip 24.2 from D:\a\_work\1\s\artifacts\Python\Lib\site-packages\pip (python 3.12)
Non-user install because user site-packages disabled
Created temporary directory: C:\Users\cloudtest\AppData\Local\Temp\pip-build-tracker-9hjc5ufp
Initialized build tracking at C:\Users\cloudtest\AppData\Local\Temp\pip-build-tracker-9hjc5ufp
Created build tracker: C:\Users\cloudtest\AppData\Local\Temp\pip-build-tracker-9hjc5ufp
Entered build tracker: C:\Users\cloudtest\AppData\Local\Temp\pip-build-tracker-9hjc5ufp
Created temporary directory: C:\Users\cloudtest\AppData\Local\Temp\pip-install-8u39htfy
Created temporary directory: C:\Users\cloudtest\AppData\Local\Temp\pip-ephem-wheel-cache-0fijydv4
Processing d:\a\_work\1\s\src\azure-cli
  Added file:///D:/a/_work/1/s/src/azure-cli to build tracker 'C:\\Users\\cloudtest\\AppData\\Local\\Temp\\pip-build-tracker-9hjc5ufp'
  Created temporary directory: C:\Users\cloudtest\AppData\Local\Temp\pip-build-env-trza6ryi
  Installing build dependencies: started
  Running command pip subprocess to install build dependencies
  error: subprocess-exited-with-error
  
  pip subprocess to install build dependencies did not run successfully.
  exit code: 57005
  
  See above for output.

Related issue: Azure/azure-cli#29887

Expected behavior

pip can also use isolated flag in build env

pip version

24.2

Python version

3.12.7

OS

Windows

How to Reproduce

It seems -I is not passed in build env.

def _install_requirements(
pip_runnable: str,
finder: "PackageFinder",
requirements: Iterable[str],
prefix: _Prefix,
*,
kind: str,
) -> None:
args: List[str] = [
sys.executable,
pip_runnable,
"install",
"--ignore-installed",
"--no-user",
"--prefix",
prefix.path,
"--no-warn-script-location",
"--disable-pip-version-check",
# The prefix specified two lines above, thus
# target from config file or env var should be ignored
"--target",
"",

Output

No response

Code of Conduct

@bebound bebound added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Oct 17, 2024
@notatallshaw
Copy link
Member

The only real workaround to pass in something to an isolated build is to export environmental variables.

So you would need to go through each option and where possible set what you though was best, e.g. PYTHONNOUSERSITE=1, PYTHONSAFEPATH=1.

I don't know whether this was considered in the design of isolated build mode, one could see why it might be a good thing to have Python isolated mode on by default for isolated builds, but there may be a good reason it isn't.

@bebound
Copy link
Author

bebound commented Oct 18, 2024

Thanks for your reply. -I implies -E, -P and -s.

PYTHONNOUSERSITE=1 equals -s, and PYTHONSAFEPATH=1 equals -P.

Although the sys.path doc does not explain why C:\\hostedtoolcache\\windows\\Python\\3.12.6\\x64\\Lib is in the path, it can be removed with -E option.

-E
Ignore all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME, that might be set.

Since -E means ignore PYTHON* env, so I don't think there is an alternative env variable for this option.

Finally, I managed to remove C:\\hostedtoolcache\\windows\\Python\\3.12.6\\x64\\Lib by explicitly set PYTHONHOME to embedded Python directory.

@bebound bebound closed this as completed Oct 23, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants