I have a Windows box with cygwin, python and django installed.
Now I want to run django-admin, but when I do I get the error:
$ django-admin.py
c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory
From here
For Windows users, who do not have symlinking functionality available, you can copy django-admin.py to a location on your existing path or edit the PATH settings (under Settings - Control Panel - System - Advanced - Environment...) to point to its installed location.
hope this helps
I just ran into the exact same problem. I've found that if you already have the windows version of python installed, it seems to get priority over the cygwin version. I solved the problem by editing /etc/profile and changed:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH
...to:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:
...which I think stops cygwin from adding the normal windows path. Once you've got that working, download django into some directory, move into that directory and type:
python setup.py install
I was having problems to begin with because I had omitted the 'python' bit at the start
As for the step on how to start your django in cygwin
first open your windows command prompt
then register the python environment by doing this:
Path %path%;C:\Python27;C:\Python27\Scripts
then now go to the installation folder of your cygwin
cd C:\cygwin
then run the cygwin.bat like this:
C:\cygwin>cygwin.bat <enter>
then cygwin will open, and type python to see if it now working
$ python
Voila we are done!
Sort of sounds like the windows version of Python is trying to run instead of the cygwin one. What happens if you type this:
$ python django-admin.py
Here I'm assuming
$ which python
Finds the cygwin version of python (which will be something like /usr/bin/python).
You may also try (temporarily) uninstalling the windows version of python and use only cygwin.
Help us help you. Is there a reason why you are running the windows python interpreter (c:\Python26\python.exe) as oppose to the cygwin python interpreter (/usr/bin/python.exe)? That could be your problem. So to troubleshoot that, you might consider removing the windows native interpreter or simply making sure the cygwin path is listed before the c:\Python26 path in the windows global PATH variable.
Add the location of your django/bin folder (or wherever else you keep django-admin.py) to your PYTHONPATH environment variable.
Like Brian mentioned you are running the Windows version of Python which won't work with the Cygwin installation.
A word of warning. When I first started using Django, I tried installing it in Cygwin and had a variety of problems and ended up switching to the regular Windows version of Python. Unfortunately, I didn't document all my issues, but I remember some of them had to do with the database libraries. Anyway, that was a few months ago when I knew less about Django than I do now. Maybe the problems I ran into have been solved and perhaps now that I know more I could get it to work, but running Django on Cygwin does seem to be the road less traveled. Good luck. :)
Just copy the django-admin.py to the current location you are working on for e.g
on Cygwin:
<root>/projects/
on your windows directory it will look like this:
C:\cygwin\home\<your computer name>\projects\
once you copy the file, you can create your project by typing this command:
$ python django-admin.py startproject mysite
and that's all - you have completed your first project using the Cygwin linux-like environment.
Add two lines to .bash_profile and .bashrc files (view their difference here). You can find them in C:\cygwin\home\[username]:
export PATH=$PATH:/cygdrive/c/python2.7
export PYTHONPATH=$PYTHONPATH:/cygdrive/c/python2.7/Lib/site-packages
Hope this helps
Related
I was trying to download a GUI, but the terminal kept giving me this error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
I'm trying to install it using this command:
python -m pip install --upgrade pip setuptools virtualenv
Check your Python version and be sure it is installed on your machine
Check the path environment variable
Go to -> "start" and type "Manage App Execution Aliases". Go to it and turn off "Python"
I was having the same issue and I fixed it by using the below method.
Copy two paths of Python
C:\Users\Maninder\AppData\Local\Programs\Python\Python39
C:\Users\Maninder\AppData\Local\Programs\Python\Python39\Scripts
These are the paths where your Python interpreter is installed. Now add this path into your environmental
variable. Put this path into System variable, not in user variable. I was using user variable, so I was facing the issue.
I have a solution for you. Make sure you check the path mark during installation. Then you need to go to Manage App Execution Aliases.
Simply go to your search bar and search for Manage App Execution Aliases. You will find the attached screen and you need to turn off App Installers as you see on the screen. Also, see the path,,, follow Maninder's answer.
Then you are good to go! :)
I had the same issue. In Windows CMD, only: py --version, works.
I tried adding the path on System variables, and it didn't work. If you are using PyCharm as I do, try to run all commands from the IDE's terminal. It usually is on the side bar where the Run and the Console is. If it is not, go to: menu View → Tool Windows → Terminal. It worked just fine for me.
You need to download Python from https://python.org. When in the installation, be sure to check the option that adds Python to PATH.
I haven't gotten this error before and have been using Python a long time, and then suddenly it showed up. I think that it is a result of a Windows update designed to steer you to their store.
In any case: to remedy the problem, go to Settings → app execution aliases → and turn "off" Python. (What they tell you to do, in other words). This should resolve the problem.
If you have installed Python successfully with add python path, ticked on, and have added
C:\Users\<user>\AppData\Local\Programs\Python\Python39
C:\Users\<user>\AppData\Local\Programs\Python\Python39\Scripts
to the path into System variables and have turned off the "aliases" and they all didn't work, you can simply use python instead of python3 in your cmd command.
Check the Aliases for App Execution in Windows. Search for Alias App in your Windows toolbar to find the UI for this. Try turning off anything Python related.
Try adding the following to your "Path" environment variable:
C:\Users\Default\AppData\Local\Programs\Python\Python37
C:\Users\Default\AppData\Local\Programs\Python\Python37\Scripts
Replace Python37 with your own version.
I solved this problem for Visual Studio Code with just writing "python" in the console:
python
After that, Microsoft Store opens automatically with the Python app:
And I just click Get.
And it all work!
All the previous answers are correct, but in my case, I was getting this, because I was not passing the version...
The fix is passing the version:
py.exe -3 your_program
If you're on Windows, you may want to use the Python installer, in Windows Marketplace.
I faced the same error while using Anaconda and trying to link the Python executable path in the command prompt.
It got rectified by going to Settings → App execution aliases → and turning "off" Python. Then again I had to set the path for Python in Anaconda and was successful in executing "python --version" command.
The same thing happened to me even after trying all the above-mentioned steps.
I just restart my system and it was working fine. Do it and if still doesn't fix the issue then make sure you have checked "add python ( any version ) to PATH" before installing Python.
If none of the previous answers are working, you can check if you have the Python executable in your program files.
Go to C:\Program Files and check if you have the Python application. If not, go to the python download website here and download the .exe file.
While installing you must select "Custom install" and select the location as C:/Program Files.
Install it and it should work now from anywhere. This worked for me!
To sincerely resolve this issue, do the following:
Uninstall the Python instance and reinstall it. Note: Make sure you check
"Add variable PATH".
On the command line, type:
python -m pip install --upgrade pip setuptools virtualenv
I got this issue when I used Visual Studio Code as the IDE, and Anaconda as my Python compiler. And you don't need to close the "app alias" in settings, but copy your python.exe to python3.exe in your Anaconda folder.
That happened to me. So, to fix it, you have to follow the following steps:
Uninstall the Python version you already installed.
Go ahead and open the installation file to reinstall it again.
Before hitting Install Now, make sure to tick the box in front of Add Python to path.
Go ahead and complete the installation procedure as usual.
Steps for installing Python
The problem is more subtle than it seems.
For example, if you are using Visual Studio Code on the bottom left, you should see Python X.X.X xx-bit (the X is the version).
If you click in there you will see where the IDE is getting the python.exe from.
Locate that folder into your file explorer and then just follow the answer that is saying to change the environments variables.
So copy the path where python.exe is and add it to the Path variable and do the same where the Script folder is (it is in the same directory where the python.exe is).
Then of course make sure your IDE is using the right Python.
None of the answers here worked for me. I did this and the error went away.
For Windows 11 which I was using, I reran the python-3.10.5-amd64.exe file from my downloads directory and then chose to modify the installation.
Then I followed these easy steps.
Make sure the PIP component is checked before proceeding to install.
Then check 'Add Python to environment variables' if it's not checked already.
Proceed to Install.
At this point, your error will be solved
If you already have the Python executable on your machine and you are getting this error in Windows 10, search for the Python executable and copy its path then copy the path in system variables. It worked for me.
to check in windows
py --version
or restart your pc first then put htis command again
When I switch my PyCharm to use Python 3.4.3 and I am getting the error:
Invalid Python SDK
Also PyCharm does not automatically find the Python 3.4 interpreter for me, even though it is on the desired path /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4. See the screenshot:
Despite this the interpreter does work. I am able to get correct output as expected, but code completion related to Python 3.4 is not working.
E.g. print("hello world!) still shows an error on the editor, but the console shows the correct output.
This also happened to me. I renamed a repository and then my virtual environment got stuck in the old path.
I grepped all configuration files and could not find any reference to the old one.
What finally solved the problem was to clear caches with the option File > Invalidate Caches / Restart...:
I had the same issue.
Try to comment/remove the PYTHONPATH variable in your ~/.bash_profile
#export PYTHONPATH=/usr/local/lib/python2.7/site-packages/
If it does not help it also may be useful to look in the idea.log for the errors:
/Users/username/Library/Logs/PyCharm40/idea.log
I had the following errors:
Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages/"
You should `unset PYTHONPATH` to fix this.
I go the same error message in Windows version of PyCharm after I re-installed Python (3.5) on a different location. The problem was that most of my existing virtual environments registered in PyCharm were still referencing the old installation of Python.
I resolved it by deleting these existing virtual environments and creating a new one. If deleting existing interpreters (in virtual environment) is not an option, you should be able to modify them instead in File | Settings | Project Interpreter
I got the same issue, when I updated Python (3.x) version via Home brew in MacOS.
Above answers didn't work for me. But with those, I realize that, it's an issue with linking the directories. I deleted ~/.virtualenvs folder and recreated all virtual envs.
$ ls -a ~/.virtualenvs
local-dev wdias-dev
$ rm -rf ~/.virtualenvs
$ which python3
/usr/local/bin/python3
$ mkvirtualenv local-dev --python=/usr/local/bin/python3
$ mkvirtualenv wdias-dev --python=/usr/local/bin/python3
Open the PyCharm again, and it works fine.
I couldn't get anything to work, so I cloned my conda env (see how), called it something else, and then set it in PyCharm to the new one.
For me, changing the paths in ~\venv\pyvenv.cfg made PyCharm recognize the new environment after bringing my projects to a new PC.
I had the same issue in Windows10. I was so frustrated, beacause everything seems looked OK. I've added PYTHONPATH, I've restarted Pycharm and deleted old virtualenv folders and created new... It did't work.
And at the end I have just opened Pycharm in an administrator mode and it works!
When creating a new project my interpreter was set to python 2.7 so I had to change that to python3 and everything works like a charm
I got the same problem with Pop OS 21.04 and Pycharm installed via Flatpack. So i remove it and installed via Snap and started working again.
I ended up having to install Python as an admin and make sure it installed to the C:\Program Files\Python310 folder. I think The option was to make sure it installed for all users. If I installed it under for user's appdata it wouldn't work.
Once I did that I was able to point pycharm to the C:\Program Files\Python310\ for the interpreter. Pretty annoying but finally got it working
I've solved it too. Uninstalled python 3.10, installed python 3.9. Changed the python interpreter to 3.9 through pycharm setting. Created a new virtual environment.
I used Python 3.7 for many Django projects using virtual environments (venv) under Windows. The Python path was
C:\Program Files\Python37\python.exe
now I upgrated python to 3.9 and the current path is
C:\Program Files\Python39\python.exe
Now when I want to run Python in any of my past projects, for example
python manage.py runserver
I get the error
No Python at 'C:\Program Files\Python37\python.exe'
Which is quite normal.
How could I update each project in order to accept the new path? Is there a way to do this or should I better downgrade to Python 3.7 and use it forever? Renaming the folder where Python is installed doesn't seem a good idea. It must surely be a configuration file to change, a variable to set or whatever. I'm relatively new with Python and I never faced this problem before.
Could you help?
If you are using pycharm, try changing the path of base interpreter.
If you are running on command prompt set the PATH set PATH=C:\Program Files\Python39;%PATH%
I would like to know the difference in
installing Python, Paramiko packages in Cygwin and
Python is already installed in my Windows PC. I have installed Cygwin too (but without Python package) and in Cygwin terminal I do the following:
$echo "PATH=\$PATH:/cygdrive/c/Python27" >> .bash_profile
then,
source .bash_profile (after doing this I am able to run a Python script from cygwin terminal).
If the steps in point number 2 works good, then still do I need to install python packages from a Cygwin mirror site ? If I have not done it, then what I might miss while running Python through Cygwin ?
Thanks for your help.
No, you don't need to do so. In fact, CYGWIN will inherit the PC's PATH, plus with virtual PATH, you can input "echo $PATH" in CYGWIN and input "PATH" and the windows console, you could find that CYGWIN has more PATH setting than the windows. However, as you already overwrite the bash_profile, so it might not looks as what I said.
Besides, the most significant difference is that most of the CYGWIN executable files depends on CYGWIN.dll, while the typically windows files don't.
To use Python in Cygwin, you add this line to .bash_profile file.
export PATH=$PATH:/cygdrive/c/virtualenv/python2.7/Scripts
Hope for helps.
I'm trying to -learn to write and- run Python scripts on my Windows 7 64 bit machine. I installed Python in C:/Python34, and I added this to my Windows' PATH variable :
C:\Python34; C:\Python34\python.exe
(the second one is probably meaningless but I tried) and still I get this error in Windows command line :
C:\Users\me>python test.py
'python' is not recognized as an internal or external command,
operable program or batch file.
So how do I truly install Python on my Windows x64 machine ?
This might be trivial, but have you tried closing your command line window and opening a new one? This is supposed to reload all the environment variables.
Try typing
echo %PATH%
into the command prompt and see if you can find your Python directory there.
Also, the second part of your addition to the PATH environment variable is indeed unnecessary.
I had the same problem: python not being recognized, with python in the path which was was not truncated.
Following the comment of eryksun in yossim's answer:
Also, if you installed for all users you should have %SystemRoot%\py.exe, which >is typically C:\Windows\py.exe. So without setting Python's directory in PATH >you can simply run py to start Python; if 2.x is installed use py -3 since >Python 2 is the default. – eryksun
I tried to use py instead of python and it worked.
Meaning:
python setup.py build -> does NOT work.
py setup.py build -> does work.
Hope it helps
I was also having the same problem.
Turns out the path I added included '..\python.exe' at the end, which as turns out was not required. I only needed to add the directory in which 'python.exe' is in (which in my case is the Anaconda's distribution directory in Users folder), similar to what we do when installing JDK in our system's PATH variable.
Hope it helps!
It wasn't working for me even after adding the path. What finally did the trick, was changing the order of listed paths in the PATH variable. I moved %USERPROFILE%\AppData\Local\Microsoft\WindowsApps down vs. having it the first path listed there.
Environment PATH Length Limitation is 1024 characters
If restarting your cmd window does not work you might have reached the character limit for PATH, which is a surprisingly short 1024 characters.
Note that the user interface will happily allows you to define a PATH that is way longer than 1024, and will just truncate anything longer than this. Use
echo %PATH%
in your cmd window to see if the PATH being truncated.
Solution
Unfortunately, there is no good way to fix this besides removing something else from your PATH.
NOTE: Your PATH = SYSTEM_PATH + USER_PATH, so you need to make sure the combined is < 1024.
I did everything:
Added Python to PATH
Uninstall all the Pythons - Both from downloaded python.org and Microsoft Store and reinstall from python.org
Change the order of PATH
Deleted %USERPROFILE%\AppData\Local\Microsoft\WindowsApps from PATH
But nothing worked. What worked for me was:
Settings > Application > App execution aliases. Then disable all the Pyhtons from here and it worked!
Also, make sure to leave no spaces after the semi-colon.
For example, this didn't work for me:
C:\Windows\system32; C:\Python27; C:\Python27\Scripts;
But, this did:
C:\Windows\system32;C:\Python27;C:\Python27\Scripts;
I'm late to the game here, but I'd like to share my solution for future users. The previous answers were on the right track, but if you do not open the CMD as an administrator, then you will be thrown that same error. I know this seems trivial and obvious, but after spending the past 8 hours programming before attempting to install Django for the first time, you might be surprised at the stupid mistakes you might make.
I have faced same problem even though my path contains 400 characters.
Try to update the path from the command line(Run as administrator)
Command to update path: setx path "%path%;c:\examplePath"
After this command I could see that paths that I configured earlier in environment variables got updated and working.
To check the configured paths: echo %PATH%
I was facing similar porblem. What helped me is where command.
C:\WINDOWS\system32>where python
C:\Users\xxxxxxx\AppData\Local\Microsoft\WindowsApps\python.exe
C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python39_86\python.exe
On updating PATH variable to point to only one desired directory (basically I removed %USERPROFILE%\AppData\Local\Microsoft\WindowsApps from PATH) fixed my problem.
I had the same issue with Python 2.7 on Windows 10 until I changed the file path in Enviroment Variables to the folder path, ie C:\Python27\python.exe didn't work but C:\Python27\ did work.
For me, installing the 'Windows x86-64 executable installer' from the official python portal did the trick.
Python interpreter was not initially recognized, while i had installed 32 bit python.
Uninstalled python 32 bit and installed 64 bit.
So, if you are on a x-64 processor, install 64bit python.
I tried it multiple times with the default installer option, the first one, (Python 3.7.3) with both 'add to environment variable' and 'all users' checked, though the latter was greyed out and couldn't be unchecked.
It failed to work for other users except for the user I installed it under until I uninstalled it and chose "Custom Install". It then clearly showed the install path being in the C:\Program Files\Python37 directory when it was failing to install it there the other way even though the 'All Users' option was checked.
Same thing was happening with me when i was trying to open the python immediately with CMD.
Then I kept my in sleep mode and started CMD using these Key Windows_key+R, typed cmd and OK. Then the package of python worked perfectly.
Uninstall python and pyqt
Then go to pyqt setup and open installation but don't install. You will see a message box saying something like pyqt version built with python version 32bit/64bit.
Then see python version bit and download that version from python.org from all release menu.
Then first install python and then install pyqt. It will work like butter.
I spent sometime checking and rechecking the path and restarting to no avail.
The only thing that worked for me was to rename the executable C:\Python34\python.exe to C:\Python34\python34.exe. This way, calling typing python34 at the command line now works.
On windows it seems that when calling 'python', the system finds C:\Python27 in the path before it finds C:\Python34
I'm not sure if this is the right way to do this, seems like a hack, but it seems to work OK.