i've got a problem when i'm doing dev
I managed to use
python manage.py runserver in a CMD shell
but the system cant find python
How could I add python to the system dependency to make the commandline work?
There are two basic ways you can do this in Windows.
Setting the PATH in the cmd shell
The first way is only local to the CMD shell you are currently in, and will have to be done again if you opened a new shell.
You can set your PATH to include the directory where python.exe is located.
In your CMD shell you can do:
set PATH=%PATH%;C:\path\to\python\install
So if Python was installed in C:\Python27, you would do this:
set PATH=%PATH%;C:\Python27
Setting the environment for your user throughout Windows
Alternatively, you can set your PATH permanently by changing the environment variable in Windows. Setting this will affect the rest of your Windows environment.
Right click "My Computer"
Select "Properties"
Click the "Advanced" tab in the new window.
Click on the "Environment Variables" button.
Edit the variable named PATH
Information about doing the latter at Microsoft: http://support.microsoft.com/kb/310519
Related
I downloaded python 1.11 from the python website but whenever I try to launch "python" in command prompt it launches the windows store and tells me to install python.
I ran py -3 and it launches python 3.11 in the command prompt. Is this the only way to access python though why doesn't "python" work?
You need to add python to Windows PATH.
Try using windows search and search for Edit the system environment variables, and then click on Environment variables. You will see "User variables" and "System variables". Find PATH variable in both sections. If you cannot find it, Click "New...".
If you are editing existing PATH, add these 2 lines:
<Your python installation path>\Python311
<Your python installation path>\Python311\Scripts
E.g.:
C:\Users\<User>\AppData\Local\Programs\Python\Python311
C:\Users\<User>\AppData\Local\Programs\Python\Python311\Scripts
If you are creating new PATH variable, add the following line:
<Your python installation path>\Python311;<Your python installation path>\Python311\Scripts
E.g.:
C:\Users\<User>\AppData\Local\Programs\Python\Python311;C:\Users\<User>\AppData\Local\Programs\Python\Python311\Scripts
Save the variables and you can access python using python on terminals.
Note: On some windows, PATH is defined as Path.
Maybe a simple question, but I cannot figure it out. I work within Visual Studio Code on a MacBook. Within a directory I create a virtual environment and have activated that with source .venv/bin/activate scripts and everything works fine.
In the terminal I see (.venv) (base) gaston#MacBook-Pro WebScraping %
When I start visual code another time and open this same directory I do not see the (.venv) so I again give manually the command to activate.
My question is there a way to activate the virtual environment automatically when opening the directory?
VS Code Default Python Interpreter Path
You can do this in a number of ways. If your goal is to have the virtual environment selected immediately at the launch of VS Code, you will have to target that virtual environment as the Python Interpreter in VSC.
https://code.visualstudio.com/docs/python/environments
System Preferences->Settings->Python: Default Interpreter Path
You'll want to point it to your virtualenv Python installation, likely something like:
envFolder/bin/python3
VS Code Launch Configuration Python Interpreter
You can also set a specific launch configuration so that VSCode will still use your system Python instance by default; however, specific launch configurations will have the virtual environment specified.
https://code.visualstudio.com/docs/python/debugging
I did something within settings and now it works.
When I open VSC now it opens the directory and the right environment, just the way I wanted it.
Took me some while to figure what finally did the trick:
I opened settings Command + , typed env in the search box. Scrolled through the results until I saw:
Python > Terminal: Activate Env In Current Terminal
and checked the checkbox. That solved my problem.
I have installed Anaconda on my Windows 10 to install Python 3.6.
I now want to run some Python scripts like test.py.
As far as I understood, I need to initialize some system variables, but I am not really able to get the whole meaning. I can set system variables by typing sysdm.cpl at the start button. Is this the right way? Otherwise?
If you want to set env variables permanently, then yes, this is the right way (start->sysdm.cpl->advanced->Environment variables)
If you want to set some variables for just one particular session, then open cmd.exe and set variables like
set _variable_=_value_
and then run your script.
1- open cmd
2-use cd to go to the file where your script is located(cd.. to go to previous folder and cd name to go to another folder)
3-when you get there in cmd type
4-python filename.py
if you are using anaconda instead of cmd use anaconda prompt
adding python to path:
1-open windows explorer
2-on the left side left click this pc and choose properties
3-then go to advanced system settings
4-then at the bottom enviorment variables
5-if you are windows 10 there will be onedrive written at top and behind it path choose path
6-then click new
7-add python directory to the path and then python directory/scripts
https://www.youtube.com/watch?v=Y2q_b4ugPWk check this
I have just installed Anaconda on my computer because I need to use Numpy.
Well, when I use python I for some reason have to be in the same folder as python.exe and, of course, now that I want to use Anaconda I have to be in the Anaconda3\Scripts folder where python.exe isn't. This is a nightmare, how can I use anaconda with python on a windows computer? Why does it have to be so complicated?
I think you are referring to the command-line use of python?
If you have admin priviliges on your machine you can add python to your environment variables, making it available in the console anywhere. (Sorry for different spellings, I am not on an english machine)
Press Shift+Pause ("System")
Click "Advanced System Options"
Click "Environment variables"
In the lower field with "System variables" there is a variable called PATH. Append the complete path to your python.exe without the file to that by adding a ; behind the last path in the variable and then adding your path. Do not add any spaces!
Example: C:\examplepath\;C:\Python27\
When you install anaconda on windows now, it doesn't automatically add Python or Conda to your path.
If you don’t know where your conda and/or python is, you type the following commands into your anaconda prompt (it comes when you install anaconda)
Next, you can add Python and Conda to your path by using the setx command in your command prompt.
Next close that command prompt and open a new one. You should now be able to use the python command. To do this you open a command prompt and type
python nameofPythonfile.py
Source: https://medium.com/#GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444
To be able to do that in the command line you just have to add Python and also the Anaconda3\Scripts directory to your system path.
Here is a good tutorial on setting your path in Windows:
http://www.computerhope.com/issues/ch000549.htm
I have installed the Enthought Python distribution on my computer, but I don't have any idea how to use it. I have PyLab and IDLE but I want to run .py files by typing the following command:
python fileName.py
I don't know where to write this command: IDLE, PyLab or Python.exe or Windows command prompt. When I do this in IDLE it says:
SyntaxError: invalid syntax
Please help me to figure this out.
Open a command prompt: Press ⊞ Win and R at the same time, then type in cmd and press ↵ Enter
Navigate to the folder where you have the ".py" file (use cd .. to go one folder back or cd folderName to enter folderName)
Then type in python filename.py
Indeed, the command to run a Python file should be run in the command prompt. Python should be in your path variable for it to work flexible.
When the python folder is added to path you can call python everywhere in the command prompt, otherwise just in your python install folder.
The following is from the python website:
Windows has a built-in dialog for changing environment variables
(following guide applies to XP classical view): Right-click the icon
for your machine (usually located on your Desktop and called “My
Computer”) and choose Properties there. Then, open the Advanced tab
and click the Environment Variables button.
In short, your path is:
My Computer ‣ Properties ‣ Advanced ‣ Environment Variables In this
dialog, you can add or modify User and System variables. To change
System variables, you need non-restricted access to your machine (i.e.
Administrator rights).
Another way of adding variables to your environment is using the set
command in a command prompt:
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
If you do it via My Computer, then look for the line named path in Enviroment Variables. Give that the value of your Python installation folder.
Set PYTHON variable to point to the full path of python.exe.
Then type in command prompt console window:
C:\path_to_folder\ python filename.py