-
Notifications
You must be signed in to change notification settings - Fork 30k
Update Dockerfiles to install packages inside a virtual environment #39098
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
base: main
Are you sure you want to change the base?
Conversation
Hi @Sai-Suraj-27 . I have some doubts regarding this. See below. My global python is They only share the python interpreter, but all the packages are isolated. root@fc6ee5f0b28d:~# python3 -m pip freeze
uv==0.7.16
root@fc6ee5f0b28d:~# python3 -c 'import sys; print(sys.executable)'
/usr/bin/python3
root@fc6ee5f0b28d:~# UV_PYTHON=/usr/bin/python3
root@fc6ee5f0b28d:~# echo $UV_PYTHON
/usr/bin/python3
root@fc6ee5f0b28d:~# uv venv && uv pip install zipp && uv pip freeze
Using CPython 3.10.12 interpreter at: /usr/bin/python3
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
Resolved 1 package in 31ms
Installed 1 package in 3ms
+ zipp==3.23.0
zipp==3.23.0
root@fc6ee5f0b28d:~# python3 -m pip freeze
uv==0.7.16
root@fc6ee5f0b28d:~# uv pip freeze
zipp==3.23.0
root@fc6ee5f0b28d:~#
root@fc6ee5f0b28d:~# uv run python3 -c 'import sys; print(sys.executable)'
/root/.venv/bin/python3
root@fc6ee5f0b28d:~# ls -la /root/.venv/bin/python3
lrwxrwxrwx 1 root root 6 Jun 28 11:15 /root/.venv/bin/python3 -> python
|
Hi, @ydshieh. Thanks for immediate reply. I understand that in your code it is by default installing packages in the Inside the root@a7ed4cb588e7:/# ls -la .venv/lib/python3.9/site-packages/
total 20
drwxr-xr-x 2 root root 4096 Jun 28 11:35 .
drwxr-xr-x 3 root root 4096 Jun 28 11:35 ..
-rw-r--r-- 1 root root 18 Jun 28 11:35 _virtualenv.pth
-rw-r--r-- 1 root root 4342 Jun 28 11:35 _virtualenv.py
root@a7ed4cb588e7:/# ls -la /usr/local/lib/python3.9/site-packages/
total 11308
drwxr-xr-x 1 root root 4096 Jun 28 11:38 .
drwxr-xr-x 1 root root 4096 Jun 10 23:51 ..
drwxr-xr-x 2 root root 4096 Jun 28 11:38 GitPython-3.1.18.dist-info
drwxr-xr-x 2 root root 4096 Jun 28 11:38 MarkupSafe-3.0.2.dist-info
drwxr-xr-x 2 root root 4096 Jun 28 11:38 PIL
drwxr-xr-x 2 root root 4096 Jun 28 11:38 PyYAML-6.0.2.dist-info
drwxr-xr-x 2 root root 4096 Jun 28 11:38 PyYAML.libs
-rw-r--r-- 1 root root 119 Jun 10 23:51 README.txt
-rwxr-xr-x 1 root root 981728 Jun 28 11:37 _cffi_backend.cpython-39-x86_64-linux-gnu.so
drwxr-xr-x 2 root root 4096 Jun 28 11:35 _distutils_hack
-rw-r--r-- 1 root root 6573 Jun 28 11:37 _hypothesis_ftz_detector.py
-rw-r--r-- 1 root root 1214 Jun 28 11:37 _hypothesis_globals.py
-rw-r--r-- 1 root root 20112 Jun 28 11:37 _hypothesis_pytestplugin.py
drwxr-xr-x 2 root root 4096 Jun 28 11:38 _multiprocess
drwxr-xr-x 8 root root 4096 Jun 28 11:38 _pytest
-rw-r--r-- 1 root root 5783 Jun 28 11:37 _soundfile.py
drwxr-xr-x 2 root root 4096 Jun 28 11:38 _soundfile_data
drwxr-xr-x 2 root root 4096 Jun 28 11:38 _yaml
drwxr-xr-x 5 root root 4096 Jun 28 11:38 absl
drwxr-xr-x 3 root root 4096 Jun 28 11:38 absl_py-2.3.0.dist-info
..
..
.. Let me know, if I am missing something. |
Thanks for sharing. Do you know why this is happening within our docker build? Maybe we are doing something wrong there. I could take a look next week, but in case you want to dive into it. I think it is better to figure out the way so the packages are installed inside the venv, and they are used during CI runtime |
Thanks for sharing. Do you know why this is happening within our docker buold? Maybe we are doing something wrong there. I could take a look next week, but in case you want to dive into it. I think it is better to figure out the way so the packages are installed inside the venv, and they are used during CI runtime I am also a bit surprised that we don't get problems at ci runtime even with the issue you mentioned |
I am also not 100% sure but I think it is because we are doing this: |
Hi, @ydshieh. As expected this line was causing the problem: Reference: I built a Docker image by removing this line: root@9433e06e57ea:/# ls -la /usr/local/lib/python3.9/site-packages/
total 60
drwxr-xr-x 1 root root 4096 Jun 29 13:07 .
drwxr-xr-x 1 root root 4096 Jun 10 23:51 ..
-rw-r--r-- 1 root root 119 Jun 10 23:51 README.txt
drwxr-xr-x 3 root root 4096 Jun 10 23:51 _distutils_hack
-rw-r--r-- 1 root root 152 Jun 10 23:51 distutils-precedence.pth
drwxr-xr-x 5 root root 4096 Jun 10 23:51 pip
drwxr-xr-x 2 root root 4096 Jun 10 23:51 pip-23.0.1.dist-info
drwxr-xr-x 5 root root 4096 Jun 10 23:51 pkg_resources
drwxr-xr-x 7 root root 4096 Jun 10 23:51 setuptools
drwxr-xr-x 2 root root 4096 Jun 10 23:51 setuptools-58.1.0.dist-info
drwxr-xr-x 3 root root 4096 Jun 29 13:07 uv
drwxr-xr-x 3 root root 4096 Jun 29 13:07 uv-0.7.16.dist-info
drwxr-xr-x 4 root root 4096 Jun 10 23:51 wheel
drwxr-xr-x 2 root root 4096 Jun 10 23:51 wheel-0.45.1.dist-info
root@9433e06e57ea:/# ls -la .venv/lib/python3.9/site-packages/
total 11328
drwxr-xr-x 1 root root 20480 Jun 29 13:10 .
drwxr-xr-x 1 root root 4096 Jun 29 13:07 ..
drwxr-xr-x 2 root root 4096 Jun 29 13:10 GitPython-3.1.18.dist-info
drwxr-xr-x 2 root root 4096 Jun 29 13:10 MarkupSafe-3.0.2.dist-info
drwxr-xr-x 2 root root 4096 Jun 29 13:10 PIL
drwxr-xr-x 2 root root 4096 Jun 29 13:10 PyYAML-6.0.2.dist-info
drwxr-xr-x 2 root root 4096 Jun 29 13:10 PyYAML.libs
-rwxr-xr-x 1 root root 981728 Jun 29 13:08 _cffi_backend.cpython-39-x86_64-linux-gnu.so
drwxr-xr-x 2 root root 4096 Jun 29 13:07 _distutils_hack
-rw-r--r-- 1 root root 6573 Jun 29 13:08 _hypothesis_ftz_detector.py
-rw-r--r-- 1 root root 1214 Jun 29 13:08 _hypothesis_globals.py
-rw-r--r-- 1 root root 20112 Jun 29 13:08 _hypothesis_pytestplugin.py
drwxr-xr-x 2 root root 4096 Jun 29 13:10 _multiprocess
drwxr-xr-x 8 root root 4096 Jun 29 13:10 _pytest
-rw-r--r-- 1 root root 5783 Jun 29 13:08 _soundfile.py
drwxr-xr-x 2 root root 4096 Jun 29 13:10 _soundfile_data
-rw-r--r-- 1 root root 18 Jun 29 13:07 _virtualenv.pth
-rw-r--r-- 1 root root 4342 Jun 29 13:07 _virtualenv.py
drwxr-xr-x 2 root root 4096 Jun 29 13:10 _yaml
drwxr-xr-x 5 root root 4096 Jun 29 13:10 absl
drwxr-xr-x 3 root root 4096 Jun 29 13:10 absl_py-2.3.0.dist-info
..
.. Let me know if anything needs to be changed in the CI config side. |
Thanks for checking. However, I think something strange here within the docker. Because I tried to some the same thing (set UV_PYTHON=/usr/local/bin/python) in a runner (not the one used by CircleCI), and yet get which corresponding to what mentioned in uv's documentation, i.e. only the python interpreter will be linked (i.e. share the same python interpreter, but the packages will be installed in the 2 different places. I will have to check it in more details why there is an issue within docker (build). |
Hi, @ydshieh I think the reason So, in Dockerfiles whe we are setting |
Very nice, I will try it to make sure, and determine what to do 🙏 |
@Sai-Suraj-27 You are completely right about
I guess I miss this comment (or misread it). That is great. I will built the (testing) images and see if they work well when using with our CircleCI workflow. Thank you a lot for finding this, pointing out about |
Do you remember why we use Using it will install everything (packages) to the global python's site-packages, and As suggested by @Sai-Suraj-27 , we can either remove Either works for me, but maybe you can confirm we don't miss any detail why you use |
When I used |
I will try
when I am back |
I have made it to work with the It requires a bit more change to correctly use it however, and I don't think it brings a lot of value over the current approach of using the default python. @Sai-Suraj-27 / @ArthurZucker Could you take a look. |
build-doc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont mind, the choice is up to you @ydshieh !
What does this PR do?
Since we are explicitly setting this
UV_PYTHON
to use the global python interpreter in the containers. All packages will be installed globally.No use of creating a virtual environment as we are not using it anywhere. Right now it's just creating an extra virtual environment in the container with no packages being installed. So,
uv venv
can be removed.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ydshieh @Rocketknight1