-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Cannot create virtualenv for PythonVirtualenvOperator #39953
Comments
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval. |
If I follow 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 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 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 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:
|
Agree. From my understanding, we cannot provide a path using I feel, I am new to this, and not sure what happens next, can you help? |
You might want to raise a PR, or wait some who might change this behaviour. |
Started a discussion pypa/virtualenv#2731 (comment) |
Yep. Looks like indeed bug in viritualenv - and as they noticed - PR with a fix there would solve the problem. For now this is a very quick workaround to bypass virtualenv limitation:
BTW. The reason we have For example when you do this in your image, this will break things (packages will be installed by root user but not available to airflow user:
This happened often in the past that people made this mistake, so the
So another option to workaround this virtualenv error could be (and you can also attempt to make PR and test it) - is to make this script available on PATH somewhere outside of /root/bin and remove |
Thanks @potiuk for the detailed information. |
is this solved yet? |
Look at the linked issue in virtualenv. It's a virtualenv issue. You might comment there. |
Closing this as it is a virtualenv issue, tracked under pypa/virtualenv#2731 (comment) |
It seems it got fixed in v20.27.0: |
Nice! |
Apache Airflow version
2.9.1
If "Other Airflow 2 version" selected, which one?
No response
What happened?
Using the docker image
apache/airflow:slim-2.9.1-python3.12
I installed an alternate Python version 3.9.
When using the PythonVirtualenvOperator in a DAG
The DAG fails with an error
What you think should happen instead?
The command for the creation of virtualenv should have been successful
How to reproduce
Non-optimised Dockerfile created only for simulating the behaviour
docker run -it <image_name:tag> bash
python -m virtualenv /tmp/venviplvcl3b --python=python3.9
/root/bin
Operating System
MacOS
Versions of Apache Airflow Providers
Not applicable
Deployment
Other Docker-based deployment
Deployment details
Extending
apache/airflow:slim-2.9.1-python3.12
and then running a webserver, scheduler & workerAnything else?
The user
airflow
has a path/root/bin
on its $PATH but does not have access to this directory, can this be the cause of the error?Discussion #39905
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: