17

I am trying to use twine to publish my first python package on pypi (of course will add on test-pypi first).

I followed the official guideline on https://packaging.python.org/tutorials/packaging-projects/.

But for some reason, twine is not found or not properly installed.

I installed twine using:

pip install twine

"pip list" says twine is installed on pip.

After I upgraded twine and everything, when I tried to run:

twine upload --repository-url https://test.pypi.org/legacy/ dist/*

then it says that twine is not found at all:

-bash: twine: command not found . 

My system is mac (high sierra) and I am using python2.7 by conda. Pip is also configured to conda python:

>>pip -V 
>>pip 10.0.1 from /anaconda2/lib/python2.7/site-packages/pip (python 2.7)

I would appreciate your help.

peterpark828
  • 177
  • 1
  • 1
  • 9
  • 14
    Does `python -m twine` instead of just `twine` work? (This isn't a complete answer, it's a question for debugging information—but if it works, it's also a workaround you can use until you get things fixed.) – abarnert Jul 21 '18 at 01:16
  • 3
    Because pip installed it, does not mean it exists on the PATH – OneCricketeer Jul 21 '18 at 07:48
  • 2
    Use `pip show -f twine` to list all files belonging to package. This will show you the relative path to the executable (smth like `../../bin/twine`). Combine it with the path printed in the `Location:` line to get the full path to the bin dir. Then add the dir to `PATH`: `PATH=$PATH:/path/to/bin twine -V` should run fine. Afterwards, persist `PATH` changes in the `.bash_profile` by adding the lines `PATH=$PATH:/path/to/bin` and `export PATH`. Restart the terminal and you're good to go. – hoefling Jul 21 '18 at 08:40
  • @abarnert your workaround works for me now. Thank you! – peterpark828 Jul 21 '18 at 14:12
  • @hoefling I added the path as you suggested and confirmed that the path is added to that location as I just checked by 'echo $PATH'. Still twine gives me no command found... :( – peterpark828 Jul 21 '18 at 14:13
  • Can you paste the output of `echo $PATH`? – hoefling Jul 21 '18 at 14:16
  • `/anaconda2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/peterpark/.local/lib/python2.7/site-packages`. The location was `/Users/peterpark/.local/lib/python2.7/site-packages` – peterpark828 Jul 21 '18 at 14:17
  • @hoefling When I added the path, I did `PATH=$PATH:/path/to/bin` instead of `PATH=$PATH:/path/to/bin twine -V` because that also gave me `-bash: twine: command not found` – peterpark828 Jul 21 '18 at 14:25
  • You did not what I suggested, that's why it didn't work. Take the `site-packages` dir and the relative path of the executable and resolve it against the location dir. Example: location `/foo/bar/site-packages`, executable `../../bin/twine`. The dir to add to `PATH` is `/foo/bin` (two levels up from `site-packages`, then descend into `bin`). Remove the `site-packages` dir from `PATH`, add the right dir and it will work. – hoefling Jul 21 '18 at 14:33
  • Based on the location path, the correct dir should be `/Users/peterpark/.local/bin`. – hoefling Jul 21 '18 at 14:35

3 Answers3

28

Use python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

Lev Zakharov
  • 2,409
  • 1
  • 10
  • 24
Iman
  • 474
  • 6
  • 5
2

Based on @hoefling comments run

pip show twine

That will list all files that belong to the twine package. It will output something like this:

Name: twine
Version: 1.12.1
Summary: Collection of utilities for publishing packages on PyPI
Home-page: https://twine.readthedocs.io/
Author: Donald Stufft and individual contributors
Author-email: donald@stufft.io
License: Apache License, Version 2.0
Location: /Users/hakuna.matata/.local/lib/python3.6/site-packages
Requires: pkginfo, readme-renderer, tqdm, requests, requests-toolbelt, setuptools
Required-by: 

Note the first file under Files which is ../../../bin/twine and Location: /Users/hakuna.matata/.local/lib/python3.6/site-packages. Of course your user name will replace 'hakuna.matata'

That will lead to a path to package executable at /Users/hakuna.matata/.local/bin which you can add it to your .bash_profile as export PATH="/Users/hakuna.matata/.local/bin:$PATH"

Then, either restart terminal or

source ~/.bash_profile
Sean
  • 489
  • 1
  • 8
  • 29
mallet
  • 2,454
  • 3
  • 37
  • 64
0

Run this command:

python -m twine upload dist/*
Antoine
  • 1,393
  • 4
  • 20
  • 26