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 'twine' #375
Comments
Hi there @kiennt23! Thanks for letting us know about this issue! I think this may be a problem with your environment, not with twine. It seems as if your environment doesn't know how to find user-installed modules. I wonder if you could share the output of
|
I had the same problem. It turns out that $PYTHONPATH needs to have the current directory in it to support twine's relative imports. So putting: export PYTHONPATH=.:my_other_dirs in ~/.bash_profile or equivalent fixes it. |
@calocan how did you install twine? I can't imagine why this is the case |
@sigmavirus24 I followed the instructions at https://packaging.python.org/tutorials/packaging-projects/. Python was installed on OSX with brew and I used to python3 -m venv avirtualenv to create a virtual environment in which to install and run twine. |
As virtualenvs are no in that document, I still do not have enough information to attempt to reproduce this. I can use twine from a virtualenv without issue. I want to help you, but you have to help me help you |
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 There is a warning message about this in the pip output:
(Where ~ is replaced with the literal path to the home directory.) For completeness, I will mention I tried to fix this by copying over the executable, without avail.
The solution was to remove the
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 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 However, if you want to make the PyPI documentation more complete, you could update it to say:
if you are installing it into a venv, omit the Or something along those lines. |
So I'm confused as to why y'all are running into this. In searching the guide, I can't find instructions for a virtualenv until this point. Regardless, it's clear that it's not entirely clear to everyone what they should be doing so I'd suggest sending some changes to the guide to help other people avoid this same mistake. |
For myself, I could not perform the preceeding step
in my usual environment because my installed version of tensorflow has an inflexible requirement on its version of setuptools. So I span up a venv to work out of. |
This comment has been minimized.
This comment has been minimized.
I cracked the code! Simply run the command with sudo. |
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
|
To be entirely clear, twine works inside virtual environments. That's how I use twine every single time. I'm still baffled about how y'all are running into these issues installing it in a virtualenv. I'd love more detail to see if there is a bug here or a way to improve the documentation for the guide. Regardless, @bhrutledge's |
My read (not verified) of @scottclowe's comment is that |
Yes @bhrutledge, that's right. It isn't a problem with twine but with the tutorial for advising the use of the If one is inside a virtual environment created with the venv module (introduced to Python's standard library in version 3.3) and runs the command
it will give a warning message. But it will continue to try to do what you've asked for and produce this peculiar end result in which the twine package is installed to Then if you try to use the executable, you get a ModuleNotFoundError (the title of the issue). This is because (without a twine executable in your environment) the shell is finding your user's twine executable and using this. But you don't have the twine package installed for the user, only inside the environment. Note that if you do have twine installed for the user, you won't get ModuleNotFoundError but may get unexpected side-effects if the twine version installed for the user doesn't match the version you had just installed into your virtual environment. This may be why @sigmavirus24 was not able to replicate the issue. Also, note that this problem doesn't arise if you are inside a virtual environment created with virtualenv instead of with the venv module. In this situation you get an error instead of a warning, and pip refuses to install anything until you either remove the The problem really is down to pip and venv misbehaving, and is not the fault of twine at all. The documented behaviour for pip here states:
which suggests the Meanwhile, here it says:
which suggests the |
@daudn, twine does not need sudo permissions. So you shouldn't need to run twine with sudo. If you find that you do need to use sudo, it will be because you have incorrectly installed twine into your global python packages (using the incorrect command |
Aha. I had no clue the |
Hope this can help.
|
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
The text was updated successfully, but these errors were encountered: