19

I am using Ubuntu on VirtualBox. How do I add pyinstaller to the PATH?

The issue is when I say

pyinstaller file.py

it says pyinstaller command not found

It says it installed correctly, and according to other posts, I think it has, but I just can't get it to work. I ran:

pip install pyinstaller

and

pyinstaller file.py 

but it won't work. I think I need to add it to the shell path so Linux knows where to find it.

pip show pyinstaller works.

Eric Smith
  • 313
  • 1
  • 2
  • 8
  • Where `pip install` puts anything depends on whether you have a virtualenv active, where your Python interpreter (the one backing `pip`) is located, etc. BTW, "won't work" isn't a particularly helpful description -- including the specific error message in the question itself would help folks affirm that your diagnosis (that it's a missing PATH entry that's the issue at hand) is correct. – Charles Duffy Dec 16 '18 at 02:10
  • Thank you for your help. I wish I could include a better error message but that is all the terminal spits out. I’ve tried looking at other posts, and this is what I’ve concluded. I’m not sure how to change my PATH to make it work. The end game is to make a python file into an executable – Eric Smith Dec 16 '18 at 04:05
  • "exits without printing an error message or taking any apparent action" is a lot more descriptive that "won't work", should that be the actual behavior at hand. – Charles Duffy Dec 16 '18 at 20:12
  • BTW, `pip install pyinstaller` will (on Windows) generally put a `pyinstaller.exe` shim in the `Scripts` subdirectory of your Python install location (on UNIX-family systems the directory is called `bin`). Have you looked at whether it's there? – Charles Duffy Dec 21 '18 at 00:27

6 Answers6

67

You can use the following command if you do not want to create additional python file.

python -m PyInstaller myscript.py
shmsi
  • 958
  • 10
  • 9
7

Just get root access first by running sudo -i and then installing pyinstaller again:

pip3 install pyinstaller
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
shubham singh
  • 79
  • 1
  • 2
3

There is another way to use pyinstaller using it as a Python script.

This is how I did it, go through pyinstaller's documentation

Create a Python script named setup.py or whatever you are comfortable with.

copy this code snippet to the setup.py:

import PyInstaller.__main__
import os
    
PyInstaller.__main__.run([  
     'name-%s%' % 'name_of_your_executable file',
     '--onefile',
     '--windowed',
     os.path.join('/path/to/your/script/', 'your script.py'), """your script and path to the script"""                                        
])

Make sure you have installed pyinstaller. To test it:

  1. open the terminal
  2. type python3
  3. type import PyInstaller

If no errors appear then you are good to go.

Put the setup.py in the folder of your script. Then run the setup.py

This was tested in Python3.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
3

Come across the same issue today. In my case, pyinstaller was sitting in ~/.local/bin and this path was not in my PATH environment variable.

Daniel Walker
  • 6,380
  • 5
  • 22
  • 45
3

You could do a echo $PATH to see the content of it, an then create a symbolic link from one of the directories listed on $PATH to the current location of your pyinstaller:

sudo ln -s ~/.local/bin/pyinstaller /usr/local/sbin/pyinstaller

On the above case, usr/local/sbin/ is the path already listed on $PATH.

jonathask
  • 115
  • 1
  • 6
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30499176) – 2e0byo Dec 03 '21 at 19:12
  • Thanks for the feedback and for pointing out the guidelines link. I do, however, don't see why it doesn't provide an answer to what was asked. I actually got this same problem and solved it following @vincent.voyage's tip. But, as the actual solution to the problem wasn't given - just why it was happening -, I felt a complement to that answer would fit (most ideally in a comment). – jonathask Dec 03 '21 at 21:18
  • Changed the answer a bit in order to make it clearer and more informative. – jonathask Dec 03 '21 at 21:20
  • 1
    If you start an answer with 'this should be a comment but I don't have the rep' you're asking for a review of 'should be a comment' ;) I did skim the rest of your answer, but saw no reason not to vote for deletion like you asked for with that opening clarification. That said, whilst I personally would have proposed an edit to @vincent.voyage's answer, I can see what this adds---the information that one can add something to $PATH with a symlink. I guess I grew up on *nix so that's obvious to me, but no harm in saying it. ... – 2e0byo Dec 03 '21 at 21:51
  • I would reword this answer, removing the opening clarification, and noting that once you have determined that X isn't in your path, you need to add it to your path, either by editing $PATH or by symlinking. Rewritten like that on consideration I think it would fall on the 'accept' rather than 'vote for deletion' side. I am neither very experienced here nor infallible, but I'm pretty confident of that. (Doubtless there are clarificatory posts on Meta.) The comment above btw was autogenerated when I voted for deletion in the review queue. It wasn't meant to be personal :) – 2e0byo Dec 03 '21 at 21:52
  • Incidentally to clairfy, one of the reasons for deletion is 'this should be a comment'. I.e. it's site policy *not* to comment in answers, and *not* to do so to work around the comment rep limit. I agree, though, that this post need not be merely a comment. – 2e0byo Dec 03 '21 at 21:55
  • My bad. Thanks for the tips though. – jonathask Dec 04 '21 at 03:20
0

python3 -m PyInstaller file.py worked in my case on Ubuntu 22.04 LTS.

Keldro
  • 33
  • 6
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 25 '22 at 08:17