Compiling python project
Compiling python project
this is my first time on posting a thread on stackoverflow, but I have used this many times in the past. I am having a problem when compiling my python files. I have looked many times on here and on other sites on how to do this and I keep getting the same answers. For some reason, on my computer, I cannot run/install pip. Whenever I try to install pip by using the python command, it is not recognized. I saw a thread on here about using 'py' instead of 'python', this is accepted as a command but when I try to install pip it just errors. I have installed python several times and have also repaired it several times, but nothing seems to work.
Any help would be greatly appreciated!
Welcome on SO. Can you be more specific about the problem you have? What do you do (exact commands), what do you expect and what do you get (error messages, program output etc) instead?
– Roman Konoval
Aug 26 at 20:25
I am currently trying to compile a python file so I can send it to others without them needing to install python and also so my src code isn't leaked. The commands I have tried are 'python get-pip.py' and 'py get-pip.py'. The error message I get are, (python command) ''python' is not recognized as an internal or external command, operable program or batch file.' and for the py command, I get '(null): can't open file 'get-pip.py': [Errno 2] No such file or directory'
– Jake Strouse
Aug 26 at 20:30
Why are you trying those commands?
– Denziloe
Aug 26 at 20:35
@JakeStrouse Check that Python is added to your $PATH variable. If you're using a UNIX system, the command
which python
should return a file path to the directory that contains your Python executable. On Windows the command would be: where *python
– John Stark
Aug 26 at 20:41
which python
where *python
2 Answers
2
Welcome to stackoverflow!
this is an image i took from a website if you would like to use PIP
the website: https://packaging.python.org/tutorials/installing-packages/#ensure-you-can-run-pip-from-the-command-line
I took a look at the directory that you specified in your comment. Pip is not an executable file there, but rather is python source code. What I found that worked and allowed me to run Pip successfully was to import Pip as a module within the system Python environment. Then run Python specifying Pip as a loaded module using the -m
flag to call pip as an executable with its own arguments (e.g. C:Users>python -m pip --version
). The steps to set this up are included below:
-m
C:Users>python -m pip --version
Step 1: Verify that Python is installed and is added to your PATH variable
From cmd, run the command: C:Users> where python
. You should be returned a file path to the executable for Python.
C:Users> where python
If instead you receive an error message that says the following: "INFO: Could not find files for the given pattern(s)." that means that Python is not added to your $PATH variable (See below for details on how to configure your PATH variable.
Step 2: Add Pip source code as a module within Python
C:Users> python
import pip
exit()
Step 3: Validate that pip can be used as a module within Python
Run the following command to check Pip's version as a validation that Pip and Python are configured correctly: C:Users> python -m pip --version
C:Users> python -m pip --version
Validate that you are returned a version number
Configuring PATH environment variable (Windows 10)
If you don't already have a 'PATH' variable defined, click 'new' and define a name of 'PATH' and add in the file path to the Python executable as the variable's value.
Close any active Command Prompts! After making changes to your PATH variable,you will need to close any active sessions in order to allow the update PATH variable to be propagated within the session.
Open a new Command Prompt window and run the command: C:Users> where python
to verify that the your changes were made correctly, and that they have fully propagated within the system.
C:Users> where python
Thank you so much for this response, I do have some slight problems. I still cannot run the command 'pip [file]'. This is what I have done: gyazo.com/e2007febd58baa4022d2b4f576fdfcca This is my pip version and the 'where py' gyazo.com/ed700699528dd4253c6c571ae1009b0d
– Jake Strouse
Aug 27 at 3:28
In the same way that you're running the
pip --version
command as C:WindowsSystem32>py -m pip --version
, you will need to run the file command as C:WindowsSystem32>py -m pip [filename]
.– John Stark
Aug 27 at 13:21
pip --version
C:WindowsSystem32>py -m pip --version
C:WindowsSystem32>py -m pip [filename]
thanks so much for that! I do have one more small question. I used that to install pyinstaller and everything went well, it asked me to add something to the $PATH and I did that. The problem is when I direct to the file I want to compile, and I type 'py -m pyinstaller snake.py' it responds with 'C:UsersjakesAppDataLocalProgramsPythonPython37-32python.exe: No module named pyinstaller'
– Jake Strouse
Aug 27 at 19:52
If you've installed pyinstaller, and it's on your PATH, you should be able to just execute
pyinstaller snake.py
directly. Because pyinstaller is an executable file, rather than a module, you can call it directly. Just make sure you're in the directory that contains snake.py and you should be good.– John Stark
Aug 27 at 20:15
pyinstaller snake.py
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What exactly are you trying to do?
– Denziloe
Aug 26 at 20:24