twine: ModuleNotFoundError: No module named 'twine'
Run all the step in this tutorial https://packaging.python.org/tutorials/packaging-projects/, but when run the step
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
It throw this error
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Traceback (most recent call last):
File "/Users/kiennguyen/Library/Python/3.6/bin/twine", line 7, in <module>
from twine.__main__ import main
ModuleNotFoundError: No module named 'twine'
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (8 by maintainers)
I also had this issue.
The problem is following the instruction
without reading the command closely.
This (rightly) installs the twine package into the venv, but (wrongly) puts a copy of the executable in
./local/bin, which (rightly) isn’t on the path while the venv is activated.There is a warning message about this in the pip output:
(Where ~ is replaced with the literal path to the home directory.) But it is just a warning amongst a large amount of pip output and can easily be missed or overlooked.
For completeness, I will mention I tried to fix this by copying over the executable, without avail.
The solution was to remove the
--userflag so pip put the executable in the correct place.Note that you don’t get this problem with virtualenv. If you try to install into a venv with the user flag:
You get an error message, and nothing is installed.
This makes it much easier to realise the error has occurred and remove the unwanted
--userflag and try again.These are both on Python 3.5 with the latest release of pip (19.0.2).
I would say the problem lies either with venv, which should copy the behaviour of virtualenv and refuse to let pip operate inside a venv with a
--userflag, or possibly with pip.However, if you want to make the PyPI documentation more complete, you could update it to say: Install twine globally with
if you are installing it into a venv, omit the
--userflag.Or something along those lines.
I discovered this issue via @daudn’s comment. It sounds like @scottclowe identified an issue with the tutorial, rather than Twine. Maybe that should be reported/fixed at https://github.com/pypa/packaging.python.org/issues (if it hasn’t already).
For future reference: pipx is a handy tool for installing Python command-line tools in a dedicated virtual environment, with the executable on your
$PATH. For example, without an active virtual environment: