python not starting properly - python

I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run properly?

You probably need to add Python to you dos path. Here's a video that may help you out:
http://showmedo.com/videotutorials/video?name=960000&fromSeriesID=96

you can't run a command that isn't in your path. it should be set globally when you installed python.
type 'set' at a dos prompt and look at the PATH variable. c:\python25 (or whever you installed python) has to be in that variable ie PATH=c:\windows;c:\python25;... etc
if it isn't in PATH then you or the installer missed the part where you needed to set it. It can be done from the 'Environment Variables' button in the 'System' control panel.

Either use the system control panel to set the PATH environment variable that applies permanently or
Reinstall Python as a system administrator so that the installer can set the registry and environment variables for you.
If you install the "just for me" option, then you have to set the PATH variable in the control panel.

In your path, I think you need to have both the location of the Python install and the Python\Scripts folder. For example, on XP, I have C:\Python25;C:\Python25\Scripts. Can you verify that you have both?

Related

Python 3.9.1 path variable

Good day!
Installed the Python 3.9.1, checked "Add to path", the cmd did not work though.
Added Environment Variable Path, both folder
C:\Users\XXXXX\AppData\Local\Programs\Python\Python39
(file manager opens the path to python.exe just fine)
and script lines:
C:\Users\XXXXX\AppData\Local\Programs\Python\Python39
Still the commands python -version and pip --version do not work from the command line.
Py --version works just fine though.
Anyone might share and idea what might be the reason?
This happens more often than one would think.
When you installed python from python.org and follow the installer, post install, you should check your environment variables, and verify that you have no other python installation (or if you do just name them appropriately).
Often you can find that there is an Environment Variable, that includes a python version on the global Environment Variable Path.
To verify that you are targeting the correct python version put these two directories (replace, user and python version), at the top of your PATH (user's path), and check that there are no conflicts with the rest of the PATH variables.
C:\Users\XXXXX\AppData\Local\Programs\Python\PythonXX
C:\Users\XXXXX\AppData\Local\Programs\Python\PythonXX\Scripts
If you had Python installed in the system before, the new path is added at the end of PATH system variable and when system looks for python.exe it finds first the old version that is available under a different folder.
If you used a command window opened before the new version got installed, it is also possible that system variables did not reload. Close it and use a new one to check.

Python 2.7 'Pip' is not recognized as an internal or external command

I tried following the instructions here with no luck.
Attached is my cmd prompt output. Any suggestions?
It looks like pip is not on your path. Try issuing the pip command again in the folder C:\Python27\Scripts.
I do not suggest using setx and it's unfortunate that search results specifically for pip point to that advice e.g. this. The truncation message to 1024 characters is real. It's very easy for that to simply knock things out of your PATH unintentionally and you might not know what got kicked out in Python's place, if it gets added at all. It will execute and then tell you the issue after the PATH has been modified. You do need to add pip to your PATH, though.
Instead, edit through right clicking My Computer and selecting "properties" (this is Windows 7):
As illustrated:
Advanced System Settings
Environment Variables
Edit the PATH for "User variables". Each path should be separated by ;.
You need to add the path to pip.exe. It's likely in the Scripts subfolder of the Python installation. You need to only provide the directory path, not reference the .exe directly.
setx does have its uses. In really locked-down systems, you can still use it without admin privileges; make of that what you will.
well, I am guessing you are using Windows system. Then I'm also guessing you specified wrong path to the pip program. Check again where is your pip.exe located and add this location to the PATH instead.
The faster way is to reinstall python, and click on the box in the installer that says:
Add Python X.X to PATH

The Python executable is not recognized on Windows 10

I recently installed Python 3.6.3 on my device. When I type python in my cmd window, it gives me this error. I do have the PATH in the environment variables. Path Lists. This should normally fix it, but python is still not recognized.
I had the same problem, due to a stupid decision from Microsoft.
I had another line in my system path variable:
C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps
And Windows 10 put a python.exe file there that only redirected me to the Python page of the Microsoft Store:
Since this line was above my true Python path, typing python in the cmd prompt opened the Microsoft Store...
Solution:
Type App execution aliases in the Windows 10 search bar, and then uncheck the aliases for python.exe and python3.exe. More information is here.
The path to the Python executable needs to be in the System PATH variable. Note this is not the User PATH variable.
The OP had Python 3.6.3 installed in C:\Python\Python36-32, however a common default location for installation is in the users AppData\Local\Programs\ folder. This post will assume a Python 3.10 installation in this location. Please adjust as needed for your current Python version and path.
You can confirm the path from the command prompt by checking the Python executable directly from the folder.
cd %LOCALAPPDATA%\Programs\Python\Python310
python --version
This should print the Python interpreter version. For example, Python 3.10.4.
Add the following entries to the System PATH:
%LOCALAPPDATA%\Programs\Python\Python310 for the python executable
%LOCALAPPDATA%\Programs\Python\Python310\Scripts for tools such as pip
After adding the path to the System PATH variable, make sure you close and reopen any command prompts, so they use the updated PATH.
If it is still not working, as mentioned in the previous answers, then simply move up the path, as shown in the screenshot.
You get this error, because the python.exe path has not been added to the System environment variable. To do that, simply:
go to the path C:\Users\%Username%\AppData\Local\Programs\Python\Python37-32 which contains python.exe
copy the path and open System environment variables and in the variable section look for variable called Path. If not, create a new variable with Variable Name as Path and value as the copied path
Once you do that, close the window and simply open cmd. Type python and you should get something like this:
If you are trying to install the new Python version, python-3.9.6, then click the checkbox of Add Python 3.9 to PATH
This happens because the path doesn't exist in environment variables.
To fix this:
Rerun the installer
Choose Modify
In optional feature click "Next"
In advanced option tick the "Add Python to environment variables"
Install
All the answers on Stack Overflow_ about it were obsolete, so I decided to add this. The path variable that needs to be added is,
C:\Users\Username\AppData\Local\Programs\Python\Python36-32
Note that everyone may have a different Username.
If you are working with the command prompt and if you are facing the issue even after adding the Python path to system variable PATH:
Remember to restart the command prompt (cmde.exe).
I too was struggling with this issue, and everything was configured correctly. I installed and setup my system path variables as one would. And everything was fine. Then upon reboot windows would not recognize 'python' as a command as if it were unaware of the path variable. Double checked to confirm everything was still setup correctly (it was).
It only started to work again after I manually browsed to the directory in which python.exe existed, and ran 'python'. After that windows seemed to recognize my path variable and I could call 'python' from where ever need be. Very odd. Figured I'd share in case someone else runs into this.
For Python 3.6, there are actually two path entries. Also, it's best to use the %USERPROFILE% rather than hard coding it.
%USERPROFILE%\AppData\Local\Programs\Python\Python36
%USERPROFILE%\AppData\Local\Programs\Python\Python36\Scripts

working with virtualenv without Python in Windows path

I have to do some work with a company with security restrictions on their computers.
I need to set Python2.7 virtualenv on their Windows10 machine but can't add python to Windows path. I installed Python through the Windows Software Centre. The interpreter is in usual C:\Python27\python.exe but it is not added to Windows path. When I run python in CMD it is not recognizable although C:\Python27\python opens the interpreter.
The problem is that to add it to Windows path I need admin privileges. It is simply not possible. I know the obvious answer is to contact admin but again it is not an option.
So the problem is, having this setup I need to install virtualenv, inside create all my environment and work on it.
I can't find the way to do it without Python in the path.
I usually install several system-wide pythons versions on my windows boxes with the only purpose of creating virtualenvs and that's more than ok. In fact, i strongly recommend to avoid polluting PATH with system-wide python paths at all. Using just virtualenvs is really a good way to go.
That said, if you're creating virtualenvs manually (ie: not using any IDE/plugin to manage this process for you) you can just do it on the command prompt like this:
> cd c:\python27\Scripts
> pip install virtualenv
and then just using c:\python27\Scripts\virtualenv.exe to create your new virtualenvs, for instance, something like this would do it:
> c:\python27\Scripts\virtualenv --python=c:\python27\python.exe foo_venv
That said, if it's more convenient for you to have virtualenv executable reachable from the console (ie: where virtualenv finds its path) you can just add it temporarily to your console session with something like:
SET PATH=%PATH%;C:\Python27\Scripts
Or even better, just create a shortcut of one bat file which spawns your favourite console (cmd prompt, conemu, ...) setting PATH on that particular session, that way you don't need to persist the variable PATH with admin privileges.
You could run: SET PATH=%PATH%;C:\Python27\ from a command prompt and it will add the python to path temporary (i.e will be gone when the command prompt is closed)

Can't find my PYTHONPATH

I'm trying to change my PYTHONPATH. I've tried to change it in "My Computer" etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search for the word 'PYTHONPATH', but to no avail.
However, it Python I can easily see it exists. So where is it?
At runtime, you can change it with:
import sys
sys.path.append('...')
In My Computer, right-click Properties (or press Win-Break), System tab, Environment Variables, System. You can add it if it's not already there.
Finally, in the CMD prompt:
set PYTHONPATH C:\Python25\Lib;C:\MyPythonLib
Or in bash:
PYTHONPATH=/usr/share/python/lib:/home/me/python
export PYTHONPATH
Or, more succinctly:
export PYTHONPATH=/home/me/python
Python does some stuff up front when it is started, probably also setting that path in windows. Just set it and see, if it is changed in sys.path.
Setting environment variables in the Python docs say:
My Computer ‣ Properties ‣ Advanced ‣ Environment Variables
You can add it under "My Computer" if it doesn't exist. PYTHONPATH just adds to the default sys.path.
On unix/linux/osx you can:
$ export PYTHONPATH=/to/my/python/libs
You can also use .pth files to point to libraries:
http://docs.python.org/library/site.html#module-site
And of course:
import sys
sys.path.append('/path/to/libs/')
Also, check out virtualenv for managing libraries for multiple projects.
Here's how I solved it.
First, get the current path. There's a lot more there than I expected.
import sys
print ';'.join(sys.path)
Copy that result to the clipboard. Go to My Computer and create the new environment variable PYTHONPATH, and for the value paste from the clipboard. Modify as necessary.
MacOS 10.5.8, Python 2.6, Eclipse+Pydev 1.5.7
Python installation's site-package is, for example:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
create symlinks YOUR LIBRARY inside into site-package, for example:
cd /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
ln -s /path/to/YOUR/LIBRARY/ YOUR_LIBRARY_NAME
Now You can use in commandline: import YOUR_LIBRARY_NAME
run Eclipse with Pydev, go to Preferences->Pydev->Interpreter Python
remove Your Python interpreter record, if exists;
click New and add Python 2.6 interpreter path, for example:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
notice, that Eclipse Pydev display Python System Library, accept that
in Library section click New Folder and write path to YOUR LIBRARY, for example:
/path/to/YOUR/LIBRARY/
click Apply - it is essential, because Eclipse Pydev built now his own "library map", when this operation finish - click [OK]
close Eclipse
run Eclipse again - now You should use in Pydev: import YOUR_LIBRARY_NAME
And, as with all good things in life, you can find it in the documentation:
http://docs.python.org/install/index.html#modifying-python-s-search-path
What's it set to? Have you tried creating a PYTHONPATH environment variable?
You need modify your environment variables. How to do this depends on which version of Windows you have.
If the PYTHONPATH variable doesn't exist, you have to create it. It might not exist if you haven't already created it.
I had same problem and oliver-zehentleitner's answer in github solved my problem.
He said: Maybe You install package with pip for python2 and run with python3, just try to install with pip3 or python3 -m pip install python-binance and then run your script again.
I hope this can solve yours too.

Categories