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

Making a virtualenv in the project root fails if <cache-dir>/virtualenvs does not exist #1573

Closed
3 tasks done
willfrey opened this issue Nov 12, 2019 · 9 comments · Fixed by #1682
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected
Milestone

Comments

@willfrey
Copy link
Contributor

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: macOS Catalina (10.15.1)
  • Poetry version: 1.0.0b3
  • Link of a Gist with the contents of your pyproject.toml file: N/A

Issue

It appears that if poetry has never made a virtualenv for you—which means that <cache-dir>/virtualenvs does not exist, then asking poetry to make a virtualenv in the project root will fail.

$ poetry env use python3 -vvv                                                                           11:12:03
Creating virtualenv autoencoding in /Users/will.frey/Desktop/autoencoding/.venv

[IOError]
[Errno 2] No such file or directory: '/Users/will.frey/Library/Caches/pypoetry/virtualenvs/envs.toml'

Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/local/bin/poetry", line 14, in <module>
    main()
  File "/Users/will.frey/.poetry/lib/poetry/console/__init__.py", line 5, in main
    return Application().run()
  File "/Users/will.frey/.poetry/lib/poetry/_vendor/py2.7/clikit/console_application.py", line 139, in run
    trace.render(io, simple=isinstance(e, CliKitException))
  File "/Users/will.frey/.poetry/lib/poetry/_vendor/py2.7/clikit/ui/components/exception_trace.py", line 57, in render
    self._render_traceback(io, tb)
  File "/Users/will.frey/.poetry/lib/poetry/_vendor/py2.7/clikit/ui/components/exception_trace.py", line 67, in _render_traceback
    io.write_line("".join(traceback.format_list(frames)))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/traceback.py", line 39, in format_list
    item = '  File "%s", line %d, in %s\n' % (filename,lineno,name)
TypeError: %d format: a number is required, not str

I can get past this by either having first made a not-in-project-root virtualenv with poetry or by creating the <cache-dir>/virtualenvs directory manually myself.

@willfrey willfrey added the kind/bug Something isn't working as expected label Nov 12, 2019
@sdispater sdispater added this to the 1.0 milestone Nov 12, 2019
@k4ml
Copy link

k4ml commented Nov 19, 2019

I have similar problem when cloning project with in-project = true in poetry.toml` and freshly setup poetry (no single virtualenv created yet). Got this error:-

git clone <url>
cd x4antispam
poetry env use python3
/home/kamal/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child proce
ss reliability may suffer if your program uses threads.
  "program uses threads.", RuntimeWarning)
No handlers could be found for logger "keyring.backend"
Recreating virtualenv x4antispam in /home/kamal/git/x4antispam/.venv

[IOError]
[Errno 2] No such file or directory: '/home/kamal/.cache/pypoetry/virtualenvs/envs.toml'
Poetry version 1.0.0b5

@k4ml
Copy link

k4ml commented Nov 19, 2019

Maybe we can skip writing the envs file in lib/poetry/utils/env.py:-

venv_in_project = self._poetry.config.get("virtualenvs.in-project")
if not venv_in_project:
    envs_file.write(envs)

@k4ml
Copy link

k4ml commented Nov 19, 2019

Ok, so one workaround is to create the "global" virtualenvs dir first:-

mkdir -p $HOME/.cache/pypoetry/virtualenvs/

@JamesHutchisonCarta
Copy link

JamesHutchisonCarta commented Jun 22, 2022

Seeing this in a dev container, on version 1.2.0b2:

>> poetry config virtualenvs.create false
>> poetry env use python
Skipping virtualenv creation, as specified in config file.

[Errno 2] No such file or directory: '/home/vscode/.cache/pypoetry/virtualenvs/envs.toml'
poetry env info

Virtualenv
Python:         3.10.4
Implementation: CPython
Path:           NA
Executable:     NA

System
Platform:   linux
OS:         posix
Python:     3.10.4
Path:       /usr/local/py-utils/venvs/poetry
Executable: /usr/local/py-utils/venvs/poetry/bin/python3.10
which python
/usr/local/bin/python
ls -ld /home/vscode/.cache/pypoetry
ls: cannot access '/home/vscode/.cache/pypoetry': No such file or directory

Strangely, when this runs in the Dockerfile that installs poetry it doesn't error, its just follow-up runs. Here's the install.

RUN python3 -m pip install --user pipx
RUN python3 -m pipx ensurepath
RUN pipx install poetry==1.2.0b2

The workaround presented, mkdir -p $HOME/.cache/pypoetry/virtualenvs/ does work.

I wonder if something is stomping on the cache directory

edit: I'm pretty sure the issue is that Github Codespaces is stomping on the cache directory

@rlaphoenix
Copy link

This issue also occurs on Read The Docs. I'm fairly certain it's an issue with poetry. Specifically only if you set poetry config virtualenvs.create false before using Poetry.

@sitbon
Copy link

sitbon commented Apr 28, 2023

This issue also occurs on Read The Docs. I'm fairly certain it's an issue with poetry. Specifically only if you set poetry config virtualenvs.create false before using Poetry.

Seeing the same in GitLab CI with both virtualenvs.create=false and POETRY_HOME/POETRY_CACHE_DIR set.

Interestingly, it seems to work fine with the same setup in Docker and POETRY_CACHE="/var/cache/poetry".

@brian-dlee
Copy link

I'm also encountering this issue when running poetry config virtualenvs.create false before first use. Mine is happening within a Docker container. Currently, I'm working around the issue with RUN mkdir -p /root/.cache/pypoetry/virtualenvs.

CleanShot 2023-04-29 at 13 41 42@2x

@Mostafa-wael
Copy link

The issue arose because I was using: poetry config virtualenvs.create false while building my Docker image in a BitBucket pipeline.
I added RUN mkdir -p /root/.cache/pypoetry/virtualenvs to my Dockerfile and the problem was solved.
Thanks to @brian-dlee and @k4ml.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants