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

ModuleNotFoundError: No module named 'cleo' #3345

Closed
3 tasks done
unknowIfGuestInDream opened this issue Nov 10, 2020 · 33 comments
Closed
3 tasks done

ModuleNotFoundError: No module named 'cleo' #3345

unknowIfGuestInDream opened this issue Nov 10, 2020 · 33 comments
Labels
kind/bug Something isn't working as expected

Comments

@unknowIfGuestInDream
Copy link

unknowIfGuestInDream commented Nov 10, 2020

  • 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: windows7
  • Poetry version: 1.1.4
  • Python version: 3.7.8

Issue

I cannot run even poetry --version now.

Traceback (most recent call last):
File "C:\Users\Administrator.poetry\bin\poetry", line 12, in
from poetry.console import main
File "C:\Users\Administrator.poetry\lib\poetry\console_init_.py", line 1, in
from .application import Application
File "C:\Users\Administrator.poetry\lib\poetry\console\application.py", line 3, in
from cleo import Application as BaseApplication
ModuleNotFoundError: No module named 'cleo'

#3071 doesn't solve my problem

@unknowIfGuestInDream unknowIfGuestInDream added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 10, 2020
@finswimmer
Copy link
Member

Hello @TaCheJW,

how have you installed or updated to the current version? What do you mean by "doesn't solve my problem" exactly? Did you uninstall poetry and tried to reinstalled afterwards?

fin swimmer

@unknowIfGuestInDream
Copy link
Author

python get-poetry.py
I download it through this command, It leads to the above problems.
I solve this problem with the following command
python get-poetry.py --version 1.0.10

@hyliu1989
Copy link
Contributor

I encounter the same problem on Windows as well. The steps leading to this were:

  1. having poetry of 1.0.10 version installed and running poetry jupyter notebook
  2. while the jupyter notebook is not shutdown, I ran poetry self update to update to 1.1.4.

After that, poetry cannot run anything, even poetry --version and I ended up had to use windows powershell to reinstall poetry. After the reinstallation, everything works fine again.

@MamadouSDiallo
Copy link

I had the same problem after updating to python 3.9 but the issue went away after "pip install --user poetry". Note that I use python through pyenv.

@muuvmuuv
Copy link

muuvmuuv commented May 15, 2021

On my Mac mini M1 using the get-poetry.py script causes the same message.

EDIT: nvm it just does not work on latest 3.10 release

@AndrewSpittlemeister
Copy link

On my Mac mini M1 using the get-poetry.py script causes the same message.

EDIT: nvm it just does not work on latest 3.10 release

I've had some success in just making a new copy of the ~/.poetry/lib/poetry/_vendor/py3.9 and renaming it to ~/.poetry/lib/poetry/_vendor/py3.10. Then I was able to get things working with a 3.10 installation (should work on windows as well). It's not great, but might be an acceptable hack until poetry updates to be compatible with 3.10.

@ElDifinitivo
Copy link

Still coming up with the issue with python 3.10 and poetry 1.1.11; I'm unable to run any poetry command.

I tried uninstalling (curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - --uninstall) and reinstalling. No issues there, all install output is error-free. Trying again to run a command shows the same ModuleNotFoundError: No module named 'cleo' exception.

The only way I can run poetry is with previous versions of python - installed with pyenv with python pinned using .python-version files in the project directory.

@dycw
Copy link

dycw commented Oct 31, 2021

@ElDifinitivo Can you explain your solution in a bit more detail?

I've tried 3.10.0 using pyenv, with .python-version pinned to 3.10.0 and pyproject.toml pinned to ^3.10.0. I am also using direnv hooked with poetry, and relaxing any of these parameters to 3.9.7 still doesn't work for me:

took 17s ❯ python
Python 3.10.0 (default, Oct 31 2021, 08:44:23) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
08:47 pre-commit-hooks dev ?1!2 p:pyenv 3.10.0
❯ cd ..
direnv: unloading
08:47 ~/work p:pyenv system
❯ cd pre-commit-hooks/
direnv: loading ~/work/pre-commit-hooks/.envrc
Traceback (most recent call last):
  File "/home/derek/.poetry/bin/poetry", line 17, in <module>
    from poetry.console import main
  File "/home/derek/.poetry/lib/poetry/console/__init__.py", line 1, in <module>
    from .application import Application
  File "/home/derek/.poetry/lib/poetry/console/application.py", line 3, in <module>
    from cleo import Application as BaseApplication
ModuleNotFoundError: No module named 'cleo'
Traceback (most recent call last):
  File "/home/derek/.poetry/bin/poetry", line 17, in <module>
    from poetry.console import main
  File "/home/derek/.poetry/lib/poetry/console/__init__.py", line 1, in <module>
    from .application import Application
  File "/home/derek/.poetry/lib/poetry/console/application.py", line 3, in <module>
    from cleo import Application as BaseApplication
ModuleNotFoundError: No module named 'cleo'
direnv: export +POETRY_ACTIVE +VIRTUAL_ENV ~PATH
08:47 pre-commit-hooks dev ?1!2 p:pyenv 3.10.0

@abn
Copy link
Member

abn commented Oct 31, 2021

@dycw can you provide the contents of /home/derek/.poetry/bin/poetry please? I have a feeling the wrong pyhton interpretor is being used because of how pyenv handles the linking.

@dycw
Copy link

dycw commented Nov 1, 2021

Hi @abn, it looks pretty empty:

❯ ls -al /home/derek/.poetry/bin/poetry
.rwxrw-r-- 457 derek  6 Oct 21:44 /home/derek/.poetry/bin/poetry

with

❯ cat ~/.poetry/bin/poetry
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import sys
import os

lib = os.path.normpath(os.path.join(os.path.realpath(__file__), "../..", "lib"))
vendors = os.path.join(lib, "poetry", "_vendor")
current_vendors = os.path.join(
    vendors, "py{}".format(".".join(str(v) for v in sys.version_info[:2]))
)

sys.path.insert(0, lib)
sys.path.insert(0, current_vendors)

if __name__ == "__main__":
    from poetry.console import main

    main()

@abn
Copy link
Member

abn commented Nov 1, 2021

Looks like the issue is the followin line.

#!/usr/bin/env python3

This means the script will attempt to use the whatever the current active python3 setup us. So, if this is not the same as the one in which you installed poetry into, the required dependencies might not be available. If installed via install-poetry.py you should get something like this.

#!/home/derek/.local/share/pypoetry/venv/bin/python
podman run --rm -i --entrypoint bash python:3.8 <<EOF
set -xe
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
cat /root/.local/bin/poetry
EOF
$ podman run --rm -i --entrypoint bash python:3.8 <<EOF
set -xe
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
cat /root/.local/bin/poetry
EOF
+ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py
+ python -
Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/root/.local/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (1.1.11)
Installing Poetry (1.1.11): Creating environment
Installing Poetry (1.1.11): Installing Poetry
Installing Poetry (1.1.11): Creating script
Installing Poetry (1.1.11): Done

Poetry (1.1.11) is installed now. Great!

To get started you need Poetry's bin directory (/root/.local/bin) in your `PATH`
environment variable.

Add `export PATH="/root/.local/bin:$PATH"` to your shell configuration file.

Alternatively, you can call Poetry explicitly with `/root/.local/bin/poetry`.

You can test that everything is set up by executing:

`poetry --version`

+ cat /root/.local/bin/poetry
#!/root/.local/share/pypoetry/venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from poetry.console import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Looks like you might have installed poetry previously usin the get-poetry.py script. I would recommend you uninstall first using that or manually removing ~/.poetry and the entry point script.

Then use the following command to install a brand new instance.

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -

Note you can modify python to python3 or to a specific executable as you desire.

@dmwyatt
Copy link

dmwyatt commented Nov 1, 2021

I can't really share the Dockerfile I'm using, but it does use poetry install. I started it out trying to use python:3.10-bullseye but got the error this issue is about. Merely switching it to python:3.9-bullseye solved the problem.

Using poetry 1.1.11

@riconnon
Copy link

riconnon commented Nov 2, 2021

I have the same issue using poetry 1.1.11 with Python 3.10

$ podman run -it --rm python:3.10.0-alpine3.14@sha256:ab08dd9e48afe4cf629d993a41dccf0a74ae08f556b25cb143d8de37b25e1525 /bin/sh
/ # wget "https://raw.githubusercontent.com/python-poetry/poetry/1.1.11/get-poetry.py"
Connecting to raw.githubusercontent.com (185.199.111.133:443)
saving to 'get-poetry.py'
get-poetry.py        100% |***************************************************************************************************************************************************************************************************************************************************************************************************************************| 31605  0:00:00 ETA
'get-poetry.py' saved
/ # python get-poetry.py --version 1.1.11
Retrieving Poetry metadata

Before we start, please answer the following questions.
You may simply press the Enter key to leave unchanged.
Modify PATH variable? ([y]/n) 

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

$HOME/.poetry/bin

This path will then be added to your `PATH` environment variable by
modifying the profile file located at:

$HOME/.profile

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing version: 1.1.11
  - Downloading poetry-1.1.11-linux.tar.gz (64.48MB)

Poetry (1.1.11) is installed now. Great!

To get started you need Poetry's bin directory ($HOME/.poetry/bin) in your `PATH`
environment variable. Next time you log in this will be done
automatically.

To configure your current shell run `source $HOME/.poetry/env`

/ # source $HOME/.poetry/env
/ # poetry init
Traceback (most recent call last):
  File "/root/.poetry/bin/poetry", line 17, in <module>
    from poetry.console import main
  File "/root/.poetry/lib/poetry/console/__init__.py", line 1, in <module>
    from .application import Application
  File "/root/.poetry/lib/poetry/console/application.py", line 3, in <module>
    from cleo import Application as BaseApplication
ModuleNotFoundError: No module named 'cleo'
/ # 

It seems that the poetry tarball that is installed has a vendor folder per Python version and 3.10 is not included.

@Kurt-von-Laven
Copy link

Kurt-von-Laven commented Nov 15, 2021

I experienced this as well when upgrading from Python 3.9.7 to 3.10.0, but not when upgrading to 3.9.8, @riconnon.

@abn
Copy link
Member

abn commented Nov 18, 2021

@riconnon @Kurt-von-Laven @TaCheJW I'd suggest you remove any existing Poetry installation and then install Poetry again either via pipx or via the installer (as follows).

curl -sSL https://install.python-poetry.org/ | python3 -

Make sure you add the relevant bin directory to your path.

Closing this for now as get-poetry.py is deprecated and the "platform" artifacts are problematic in general.

@abn abn closed this as completed Nov 18, 2021
@dmwyatt
Copy link

dmwyatt commented Nov 18, 2021

@abn I did use pipx

@abn
Copy link
Member

abn commented Nov 18, 2021

@abn I did use pipx

@dmwyatt I am unable to reproduce the issue.

podman run --rm -i --entrypoint bash docker.io/python:3.10-bullseye <<EOF
set -xe
pip --quiet --disable-pip-version-check install pipx
pipx install poetry
/root/.local/bin/poetry --version
EOF
output:

+ pip --quiet --disable-pip-version-check install pipx
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
+ pipx install poetry
⚠️  Note: '/root/.local/bin' is not on your PATH environment variable. These
    apps will not be globally accessible until your PATH is updated. Run `pipx
    ensurepath` to automatically add it, or manually modify your PATH in your
    shell's config file (i.e. ~/.bashrc).
done! ✨ 🌟 ✨
creating virtual environment...
creating shared libraries...
upgrading shared libraries...
installing poetry...
  installed package poetry 1.1.11, Python 3.10.0
  These apps are now globally available
    - poetry
+ /root/.local/bin/poetry --version
Poetry version 1.1.11

@dmwyatt
Copy link

dmwyatt commented Nov 18, 2021

Oops, I confused this issue for another issue I'm having in another environment that does use pipx where I keep having to delete the artifacts folder. You are correct that I'm only having this issue where get-poetry is being used.

Apologies for the noise.

@Kurt-von-Laven
Copy link

@abn, leaving this issue unaddressed presents a headache for those of us using asdf, because install-poetry.py breaks asdf (c.f., #4199). Fixing either issue (not necessarily both) would be sufficient to continue supporting installation via asdf.

@riconnon
Copy link

hmm, the issue I have with this is that if I am "using Poetry version 1.1.11" then how do I install it? becuase install-poetry.py does not exist at that version.
It seem to me that you've created a scenario where to install Poetry version 1.1.11 one is dependent on an install script from a higher, as yet unreleased, version.
Is there a plan to release a Poetry 1.1.x version (or a stable 1.2.x version) which includes the install-poetry.py script?

@abn
Copy link
Member

abn commented Nov 19, 2021

@Kurt-von-Laven I suspect improvements to how the default interpretor is detected is more likely than fixes to get-poetry.py. I haven't looked at what is going wrong with the detection, but a fix for a related issue was added to master. Try using curl -sSL https://install.python-poetry.org | python - --git <poetry git>. I can a take a look on #4199 if that does not work.

@riconnon the installer is not really tied to a poetry release. To reflect this more accurately, the installer has been moved to https://github.com/python-poetry/install.python-poetry.org. This is maintained outside of Poetry release cycles. So, you can use the install script for installing 1.1.11. In fact, this is the version installed by default today.

curl -sSL https://install.python-poetry.org | python -

@riconnon
Copy link

@abn interesting. problem is that if I curl from some random domain (eg. install.python-poetry,org) I have no way to be sure the install script still does what I expect it to do.
My ask is that I can review and be confident in the install script in the same way I am for poetry itself. Perhaps using pip and/or pipx is the answer, but it definitely feels like a retrograde step compared to what I could do before, ie.

ARG poetry_version=1.1.x
RUN wget "https://raw.githubusercontent.com/python-poetry/poetry/${poetry_version}/get-poetry.py" \
 && python get-poetry.py --version "${poetry_version}"

Now, were I to want to do similar, I would have to do independent reviews of updates to the install script from those of updates to poetry

@abn
Copy link
Member

abn commented Nov 20, 2021

Quite honestly, curling from GitHub or Poetry's official domain is not much different. Neither is signed.

And if you want to use GitHub, use the raw url from the new repo.

https://raw.githubusercontent.com/python-poetry/install.python-poetry.org/main/install-poetry.py

You can use a specific commit ID if you want consistency.

As I said before the installer is not tied to versions. And these scripts will be removed after the 1.2.0 release.

Further, if you want to secure your supply chain, you really ought to have all your wheels signed for the entire dependency chain. This includes pip and pipx.

@Kurt-von-Laven
Copy link

@abn, I may have misinterpreted, but my interpretation of #651 is that #4199 will be closed as too cumbersome to fix from a maintenance perspective as well. News to the contrary would certainly be welcome though; hopefully I am mistaken.

I'm confused as to why I ought to specify the Git repository to the install script (and which Git repository I would install besides the default one).

@abn
Copy link
Member

abn commented Nov 20, 2021

@Kurt-von-Laven I need to go through those in a bit more detail. But, as I understand it, the issue you are referring to is that when we do poetry install on a fresh clone of a project, poetry by default chooses the the python version it was installed to, instead of the common expectation that whatever python version is activated via pyenv. Is this correct?

In my mind, Poetry should work as an external tool, running in it's own environment. And it should not execute itself under the active environment but rather in it's isolated environment into which it was installed.

This should really go into a project discussion as it is off topic for this particular issue.

As for the git repo, the command would be something like this.

python install-poetry.py --git https://github.com/python-poetry/poetry.git@master

This is so that you can test if #4433 fixes anything for you. As this has not been released yet.

@Kurt-von-Laven
Copy link

Thank you, @abn. Yes, uninstalling all versions of Poetry and updating the Poetry plugin to use:

install_url="https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py"
curl -sSL "$install_url" | POETRY_HOME=$install_path python3 - --git "https://github.com/python-poetry/poetry.git@$version"

works for me. I also specified poetry master in my .tool-versions file, although one could alternatively hard-code the version directly in the install script for testing purposes. Sorry for commandeering the thread! I will refrain from opening a separate discussion since this seems resolved on my end.

@abn
Copy link
Member

abn commented Nov 23, 2021

@Kurt-von-Laven glad it is resolved. Just an FYI, the install script in the poetry repo will eventually be removed and served via install.python-poetry.org. The source for it is available at https://github.com/python-poetry/install.python-poetry.org

tony added a commit to tony/asdf-poetry that referenced this issue Nov 25, 2021
This operates independently of poetry releases so it can pull
bugfixes merged outside of poetry's own release cadence.

See also:
- https://github.com/python-poetry/install.python-poetry.org
- python-poetry/poetry#3345 (comment)

In conjunction with asdf-community#14 this gets python 3.10 working with poetry
1.1.11 where ModuleNotFoundError: No module named 'cleo' was raised.
tony added a commit to tony/asdf-poetry that referenced this issue Nov 25, 2021
This operates independently of poetry releases so it can pull
bugfixes merged outside of poetry's own release cadence.

See also:
- https://github.com/python-poetry/install.python-poetry.org
- python-poetry/poetry#3345 (comment)

In conjunction with asdf-community#14 this gets python 3.10 working with poetry
1.1.11 where ModuleNotFoundError: No module named 'cleo' was raised.
tony added a commit to tony/asdf-poetry that referenced this issue Nov 27, 2021
This operates independently of poetry releases so it can pull
bugfixes merged outside of poetry's own release cadence.

See also:
- https://github.com/python-poetry/install.python-poetry.org
- python-poetry/poetry#3345 (comment)

In conjunction with asdf-community#14 this gets python 3.10 working with poetry
1.1.11 where ModuleNotFoundError: No module named 'cleo' was raised.
tony added a commit to tony/asdf-poetry that referenced this issue Nov 27, 2021
This operates independently of poetry releases so it can pull
bugfixes merged outside of poetry's own release cadence.

See also:
- https://github.com/python-poetry/install.python-poetry.org
- python-poetry/poetry#3345 (comment)

In conjunction with asdf-community#14 this gets python 3.10 working with poetry
1.1.11 where ModuleNotFoundError: No module named 'cleo' was raised.
@tedivm
Copy link

tedivm commented Dec 5, 2021

I'm still hitting this issue and none of the workarounds solve it.

@Jonesus
Copy link

Jonesus commented Jan 20, 2022

@tedivm Did you manage to resolve the issue? I was having trouble with the same error as well, but finally I realized that my bash was using an old install of Poetry via /home/<username>/.poetry/bin/poetry instead of the new install method's /home/<username>/.local/bin/poetry. I managed to fix my problems by manually deleting /home/<username>/.poetry, running curl -sSL https://install.python-poetry.org | python3 - and then refreshing the current shell!

@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
@fastzhong
Copy link

The problem remains for python 3.11.1.

@neersighted
Copy link
Member

This issue only tracks installs with the old installer, which used a bespoke packaging format. This issue is no longer relevant as the installer has been replaced. If you are experiencing something similar, it likely is purely a local issue; try reinstalling using the recommended methods. If that doesn't solve it, you need to create a reproducer so that others can reason about your issue and help you. If you can reproduce it in a container or brand new VM, please open an issue with detailed instructions.

@crescent-bird
Copy link

@tedivm Did you manage to resolve the issue? I was having trouble with the same error as well, but finally I realized that my bash was using an old install of Poetry via /home/<username>/.poetry/bin/poetry instead of the new install method's /home/<username>/.local/bin/poetry. I managed to fix my problems by manually deleting /home/<username>/.poetry, running curl -sSL https://install.python-poetry.org | python3 - and then refreshing the current shell!

Nice approach! I solved my problem with this too. I should change .zshrc to export new path!

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

No branches or pull requests