Having trouble running django on Pycharm - python

I'm sure you guys have heard enough of these questions but I am a new programmer looking to start using Django. I have done pip install django and by the time it's almost done download I received a warning.
WARNING: The script django-admin.exe is installed in 'C:\Users\bryan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
I have ignored this earlier and ran the command django-admin startproject and of course I receive another error.
The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or
operable program.
Not quite what to do. I need your help. Or at least direct me to a post similar to this matter. Thank you!
I have tried redirecting the PATH with
pip install--install-option="--prefix=C:\Users\bryan\PycharmProjects\mySite" django
I saw this on another post and thought it would help but nothing really worked.

It looks like you have globally installed Python with locally installed Python packages.
Option 1: try doing what Windows says: add the directory with locally installed Python packages to the Windows PATH.
Option 2: consider using virtual environments: https://docs.python.org/3/library/venv.html

Related

Django runserver not working; error: Python was not found. Did I miss something?

It's been a while since I posted anything here, and now my problems have become more advanced. For reference, I'm running on Win10.
I'm trying to use the Django framework. Python's been installed on my computer forever; it's the latest version, and it's installed on environment variables/added to system paths. I think those are enabled by default, but I did make sure that they were checked when I reinstalled it.
pip's been updated too. Django installed successfully. I managed to get all the way to installing my new project with django-admin startproject PROJECTNAME, but when I try to run python3 manage.py runserver, I'm getting 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.
This "Python was not found" error is the main problem that I'm trying to figure out. Nothing I do as a fix seems to get rid of it.
...Interesting. If I type in python --version, I get a response (Python 3.11.0). Here's what I get if I do pip freeze:
asgiref==3.6.0
Django==4.1.6
sqlparse==0.4.3
tzdata==2022.7
Python IDLE runs fine; all .py files run fine. Alright. So, with that in mind and in accordance to a lot of popular advice I've seen floating around, I added the Path to my Environment Variables. For space-saving reasons, my Python is installed on my D drive rather than C. I've made sure that there weren't any leftover Python files that conflicted.
I've uninstalled and reinstalled, double checked my installations, and Django is in D:\ProgramData\Python311\Scripts with pip and everything else I need. I did also disable the shortcut from Settings > Manage App Execution Aliases, but when I did that, I got this error:
python3 : The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Based on some other things I've seen, I've also tried:
python manage.py runserver
python3 ./manage.py runserver
I ended up having to enable the options again just to use Python correctly. And I have been closing and reopening the command line whenever I make changes. Though it updates automatically to fit what I've been doing, I wanted to make sure I didn't overlook any possibility.
I even uninstalled Django for a third time, installed the virtual environment (which I realised I skipped), and did it all again. And then, after a long series of figuring out how to activate the virtual environment and enabling scripts to run, I'm finally in (venv) D:\PROJECTNAME, and I tried... to run it again.
I'm still getting the Python not found error. orz
I've been at it for two hours or so, and I feel like I'm running into a dead end. I think I've finally met my match here.
This is my first time using frameworks like this, and it's been a while since I've installed anything through command line on Windows. I'm not very great at this, so I know that I'm making some amateurish mistakes somewhere. Please let me know if I'm doing anything wrong or missed something obvious.
Please.... I just want to use Django....
Thanks in advance!
This question really is not proper for a PowerShell Q&A, but let see if the below helps.
If you are trying to run django from PS, then:
pip install django
django-admin startproject YourProjectNamehere
lastly, hit your dev server
HTTP://YourDevServerName:YourDevServerPortNumber
Also, be sure that you've activated your virtual environment, never assume it is until you test it. Of course, be sure to change directly to the root of your project.
Again, if you are using python, directly, then, it's more prudent to stay in your pristine python shell vs executing from a PowerShell consoler/terminal, thus eliminating any PowerShell particulars.
first download manually python on your computer , therefore install django from official website , www.python.org/downloads/, https://www.djangoproject.com/download/,
if you're on linux, pip install Django==4.1.6
after installing that use ,
django-admin

Python was not found error when runnig code

After a few routine windows updates, I started getting this error when I was running python code in VSCode.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
I got told to first check PATH and to untoggle Python in App Execution Aliasies. I figured that python was already added to the PATH (I had just checked the box when downloading) and that when I untoggle Python in App Execution Aliasies I get another error
'python3' is not recognized as an internal or external command, operable program or batch file.
So I'm essentially stuck between two different errors and a correct PATH and the only times when I can run a code is when I run it from the default Python IDE that comes in the download package.
Anyone know how to fix this?
PS. when I download Python from Windows Store, it works but I don't know how to use pip with it to install external packages.
Below is the pic of my PATH.
Please reinstall python. When you install python, there will be a prompt in the lower left corner to automatically add it to the environment variable. Please check it.
At the same time, please select the correct Python interpreter in vscode.
You can refer to docs for more information.

Getting error in VS code when trying to create virtual environment on windows

I am trying to create a virtual environment in VS code to make a flask app. After I run the command in the VS code terminal pip install virtualenv everything downloads find but I get the error WARNING: The script virtualenv.exe is installed in
C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Then when I try to create my virtual environment by using this command virtualenv env I get the error
virtualenv : The term 'virtualenv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Are you using Python from the Windows Store? You'd better avoid it.
You can download the python from the official site.
And then create the virtual environment through venv.
You can refer to official docs for more details of the virtual environment created.
This is happening because the directory (as mentioned by you)
C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
is not added to your PATH
Consider this link Add to the PATH on Windows 10 and add the directory to the PATH.
It's gonna solve your problem.
The same issue happened to me it solve it as said above.

PyCharm terminal doesn't recognize Python or Pip

I'm using PyCharm for a project, and I've been having a problem I can't understand. In the "terminal" (in PyCharm), I activate the virtualenv I want, which has Python and all my other packages. The project works, which means the packages are being found, because otherwise it wouldn't work. But the thing is, neither python nor pip are recognized in the PyCharm terminal. This happens whether the virtualenv is activated or deactivated, so I don't think that's the issue.
I get the "python is not a recognized internal or external command" message, but if I do it in the file system, for instance, I can use python, pip, and everything else just fine, so I think it might be a configuration of my PyCharm, most likely, but I don't even know where to look, I don't see anything in the settings that I find odd. Any help could save me a lot of time I've been stuck with this. I'm on Windows 10, by the way.
The environment variable 'PATH' is 'C:\Users\Iván\AppData\Local\Programs\Python\Python36', and python is recognized anywhere but within the PyCharm terminal.
If you are using windows.
You have to add paths to python & pip in environment variables. If you have no previous experience doing so. I would ask to use this link https://www.youtube.com/watch?v=DrhkbjDAUV0.
If I am getting your problem wrong sorry.

Python conflicts when importing?

I have windows 10 with 2 user accounts, one is an old one that has Python installed. My latest account also has Python installed. I used pip install tweepy, and it now exists in the site packages. If I open my Python shell (v3.6.5), it imports fine. However, I can't get this to work when switching to Python in cmd. In here, after typing python, it says Python 3.6.6. Obviously they are different, yet they seem to be originating from the same directory.
Any ideas?
[edit] I have just realised that I have an external application that runs on Python 3.6.6., so I guess it's defaulting because of that. However, I can't uninstall that since I need it - is there a way to specify which version of Python is launched when I type python into the cmd?
[edit2]: This is the issue, and the solution there works. However, I want to be able to just type python into cmd, rather than the entire path. Since both exist in the path (and I don't want to remove the other 3.6.6.), is there a way to achieve this?
Have you thought about using a virtual environment?
https://virtualenv.pypa.io/en/latest/
When you enter "python" into your cmd it searched python.exe in the directories listed on your PATH variable.
All you need to do is to modify your PATH and add the directory path in which the python with the desired version is located.

Categories

Resources