python-poetry / python-poetry/poetry
poetry fails with permission error, package install tries to access /usr/local
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
- Poetry version:
- Python version:
- OS version and name:
- pyproject.toml:
- I am on the latest stable Poetry version, installed using a recommended method.
- I have searched the issues of this repo and believe that this is not a duplicate.
- I have consulted the FAQ and blog for any relevant entries or release notes.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption) and have included the output below.
Issue
Using Poetry 1.4.0 or later poetry fails with a permission error trying to write to system wide /usr/local. This is running Poetry 1.4.2 with this pyproject.toml without lock file and emptied ~/.cache/pypoetry/:
% poetry install master
Creating virtualenv picard-website-LxBKNjD0-py3.10 in /home/phw/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbbResolving dependencies... Downloading https://files.pythonhosted.org/packages/7f/99/ad6bd37e748257dd70Resolving dependencies... (6.6s)
Writing lock file
Package operations: 21 installs, 11 updates, 0 removals
• Installing tzdata (2023.3): Failed
PermissionError
[Errno 13] Permission denied: '/usr/local/lib/python3.10/dist-packages/tzdata'
at /usr/lib/python3.10/os.py:225 in makedirs
221│ cdir = bytes(curdir, 'ASCII')
222│ if tail == cdir: # xxx/newdir/. exists if xxx/newdir exists
223│ return
224│ try:
→ 225│ mkdir(name, mode)
226│ except OSError:
227│ # Cannot rely on checking for EEXIST, since the operating system
228│ # could give priority to other errors like EACCES or EROFS
229│ if not exist_ok or not path.isdir(name):
With poetry 1.3.2 the same procedure succeeds without attempting to access the system wide directory:
% poetry install master
Creating virtualenv picard-website-LxBKNjD0-py3.10 in /home/phw/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... Downloading https://files.pythonhosted.org/packages/7f/99/ad6bd37e748257dd70Resolving dependencies... Downloading https://files.pythonhosted.org/packages/d5/fb/a79efcab32b8a1f1ddResolving dependencies... (7.1s)
Writing lock file
Package operations: 21 installs, 11 updates, 0 removals
• Installing tzdata (2023.3)
• Updating markupsafe (2.0.1 /usr/lib/python3/dist-packages -> 2.1.2)
• Updating pyparsing (3.0.7 /usr/lib/python3/dist-packages -> 3.0.9)
• Installing pytz-deprecation-shim (0.1.0.post0)
• Updating click (8.0.3 /usr/lib/python3/dist-packages -> 8.1.3)
• Installing exceptiongroup (1.1.1)
• Installing iniconfig (2.0.0)
• Installing itsdangerous (2.1.2)
• Installing jinja2 (3.1.2)
• Updating packaging (21.3 /usr/lib/python3/dist-packages -> 21.3)
• Installing pluggy (1.0.0)
• Updating pytz (2022.2.1 /usr/lib/python3/dist-packages -> 2023.3)
• Updating setuptools (59.6.0 /usr/lib/python3/dist-packages -> 67.6.1)
• Updating six (1.16.0 /usr/lib/python3/dist-packages -> 1.16.0)
• Updating tomli (2.0.1 /usr/lib/python3/dist-packages -> 2.0.1)
• Installing tzlocal (4.3)
• Installing werkzeug (2.2.3)
• Installing apscheduler (3.10.1)
• Installing babel (2.12.1)
• Installing coverage (7.2.3)
• Installing flask (2.2.3)
• Installing pytest (7.3.0)
• Updating python-dateutil (2.8.1 /usr/lib/python3/dist-packages -> 2.8.2)
• Installing typing-extensions (4.5.0)
• Updating blinker (1.4 /usr/lib/python3/dist-packages -> 1.6.1)
• Installing cachelib (0.9.0)
• Installing flask-apscheduler (1.12.4)
• Installing flask-babel (2.0.0)
• Installing flask-testing (0.8.1)
• Updating markdown (3.4.1 /usr/lib/python3/dist-packages -> 3.4.3)
• Installing mistune (2.0.5)
• Installing pytest-cov (4.0.0)
Here is the complete output from the first invocation with Poetry 1.4 with -vvv flag:
% poetry install -vvv 1 master
Loading configuration file /home/phw/.config/pypoetry/config.toml
The virtual environment found in /home/phw/.cache/pypoetry/virtualenvs/picard-website-LxBKNjD0-py3.10 seems to be broken.
Recreating virtualenv picard-website-LxBKNjD0-py3.10 in /home/phw/.cache/pypoetry/virtualenvs/picard-website-LxBKNjD0-py3.10
Using virtualenv: /home/phw/.cache/pypoetry/virtualenvs/picard-website-LxBKNjD0-py3.10
Installing dependencies from lock file
Finding the necessary packages for the current system
Package operations: 21 installs, 11 updates, 0 removals
• Installing tzdata (2023.3): Pending...
• Installing tzdata (2023.3): Installing...
• Installing tzdata (2023.3): Failed
Stack trace:
8 ~/.local/lib/python3.10/site-packages/poetry/installation/executor.py:280 in _execute_operation
278│
279│ try:
→ 280│ result = self._do_execute_operation(operation)
281│ except EnvCommandError as e:
282│ if e.e.returncode == -2:
7 ~/.local/lib/python3.10/site-packages/poetry/installation/executor.py:382 in _do_execute_operation
380│ return 0
381│
→ 382│ result: int = getattr(self, f"_execute_{method}")(operation)
383│
384│ if result != 0:
6 ~/.local/lib/python3.10/site-packages/poetry/installation/executor.py:502 in _execute_install
500│
501│ def _execute_install(self, operation: Install | Update) -> int:
→ 502│ status_code = self._install(operation)
503│
504│ self._save_url_reference(operation)
5 ~/.local/lib/python3.10/site-packages/poetry/installation/executor.py:560 in _install
558│ self._remove(operation.initial_package)
559│
→ 560│ self._wheel_installer.install(archive)
561│ finally:
562│ if cleanup_archive:
4 ~/.local/lib/python3.10/site-packages/poetry/installation/wheel_installer.py:108 in install
106│ except _WheelFileValidationError as e:
107│ self.invalid_wheels[wheel] = e.issues
→ 108│ install(
109│ source=source,
110│ destination=self._destination.for_source(source),
3 ~/.local/lib/python3.10/site-packages/installer/_core.py:109 in install
107│ root_scheme=root_scheme,
108│ )
→ 109│ record = destination.write_file(
110│ scheme=scheme,
111│ path=destination_path,
2 ~/.local/lib/python3.10/site-packages/installer/destinations.py:207 in write_file
205│ )
206│
→ 207│ return self.write_to_fs(scheme, path_, stream, is_executable)
208│
209│ def write_script(
1 ~/.local/lib/python3.10/site-packages/poetry/installation/wheel_installer.py:54 in write_to_fs
52│ # Due to the parallel installation it can happen
53│ # that two threads try to create the directory.
→ 54│ os.makedirs(parent_folder, exist_ok=True)
55│
56│ with open(target_path, "wb") as f:
PermissionError
[Errno 13] Permission denied: '/usr/local/lib/python3.10/dist-packages/tzdata'
at /usr/lib/python3.10/os.py:225 in makedirs
221│ cdir = bytes(curdir, 'ASCII')
222│ if tail == cdir: # xxx/newdir/. exists if xxx/newdir exists
223│ return
224│ try:
→ 225│ mkdir(name, mode)
226│ except OSError:
227│ # Cannot rely on checking for EEXIST, since the operating system
228│ # could give priority to other errors like EACCES or EROFS
229│ if not exist_ok or not path.isdir(name):
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the linked pyproject.toml using Poetry 1.4.2 and poetry install -vvv, then inspect poetry/installation/executor.py and poetry/installation/wheel_installer.py around the reported stack frames. Compare the behavior with Poetry 1.3.2; done means installation places packages in the project virtualenv without attempting to create /usr/local/lib/python3.10/dist-packages/tzdata.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100