Taragolis commented on issue #39953:
URL: https://github.com/apache/airflow/issues/39953#issuecomment-2141716454

   If I follow [installing from source 
](https://wiki.debian.org/Python#Installing_from_Source) from Debian wiki, I've 
also have the same issue.
   
   I would rather to say that is kind of a bug (or feature better ask about 
this behaviour them) of [`virtualenv`](https://github.com/pypa/virtualenv)
   
   ```console
   airflow@37a3cf621ce5:/tmp$ echo $PATH
   
/root/bin:/home/airflow/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
   
   airflow@37a3cf621ce5:/tmp$ which python3.9
   /usr/local/bin/python3.9
   
   airflow@37a3cf621ce5:/tmp$ python -m virtualenv /tmp/venv67bk3b69 
--system-site-packages --python=python3.9
   PermissionError: [Errno 13] Permission denied: '/root/bin'
   ```
   
   However if I provide a path then there is not a problem to create virtualenv
   
   ```console
   airflow@37a3cf621ce5:/tmp$ python -m virtualenv /tmp/venv67bk3b69 
--system-site-packages --python=/usr/local/bin/python3.9
   created virtual environment CPython3.9.0.final.0-64 in 472ms
     creator CPython3Posix(dest=/tmp/venv67bk3b69, clear=False, 
no_vcs_ignore=False, global=True)
     seeder FromAppData(download=False, pip=bundle, setuptools=bundle, 
wheel=bundle, via=copy, app_data_dir=/home/airflow/.local/share/virtualenv)
       added seed packages: pip==24.0, setuptools==69.5.1, wheel==0.43.0
     activators 
BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
   ```
   
   So the error happen during lookup `python3.9` in `virtualenv`, in theory it 
should skip Permission denied, or maybe use `which` command
   
   ```python
   airflow@37a3cf621ce5:/tmp$ python
   Python 3.12.3 (main, Apr 24 2024, 07:13:43) [GCC 12.2.0] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import shutil
   >>> shutil.which("python3.9")
   '/usr/local/bin/python3.9'
   >>> 
   
   >>> from virtualenv import session_via_cli
   >>> 
   >>> session = session_via_cli(["/tmp/fooobar", "-p", "python3.9"])
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/run/__init__.py", 
line 49, in session_via_cli
       parser, elements = build_parser(args, options, setup_logging, env)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/run/__init__.py", 
line 77, in build_parser
       parser._interpreter = interpreter = discover.interpreter  # noqa: SLF001
                                           ^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/discovery/discover.py",
 line 41, in interpreter
       self._interpreter = self.run()
                           ^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/discovery/builtin.py",
 line 58, in run
       result = get_interpreter(python_spec, self.try_first_with, 
self.app_data, self._env)
                
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/discovery/builtin.py",
 line 75, in get_interpreter
       for interpreter, impl_must_match in propose_interpreters(spec, 
try_first_with, app_data, env):
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/discovery/builtin.py",
 line 147, in propose_interpreters
       for pos, path in enumerate(get_paths(env)):
     File 
"/home/airflow/.local/lib/python3.12/site-packages/virtualenv/discovery/builtin.py",
 line 170, in get_paths
       if p.exists():
          ^^^^^^^^^^
     File "/usr/local/lib/python3.12/pathlib.py", line 860, in exists
       self.stat(follow_symlinks=follow_symlinks)
     File "/usr/local/lib/python3.12/pathlib.py", line 840, in stat
       return os.stat(self, follow_symlinks=follow_symlinks)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   PermissionError: [Errno 13] Permission denied: '/root/bin'
   
   >>> session = session_via_cli(["/tmp/fooobar", "-p", 
shutil.which("python3.9")])
   >>> session.interpreter.version_info
   VersionInfo(major=3, minor=9, micro=0, releaselevel='final', serial=0)
   ```
   
   Technically PythonVirtualEnvironment might be change to avoid this issue:
   - Allow to provide path to the python interpreter binary
   - Try to determine path locally before provide it into the interpreter


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to