How to run .py files on Windows/Anaconda terminal? - python

So I installed Anaconda on my computer, and use Jupiter notebook to write a script.
I have some .py files I want to run from Windows or Anaconda Terminal, just out of curiosity.
Here are the error message I got -
C:\Users\xxx\Documents>python ex1.py
'python' is not recognized as an internal or external command,
operable program or batch file.
Is there a way that I can run python on Windows without messing up the path?

I guess you are using Command prompt to parse python files.
Open Anaconda Prompt,
navigate to the folder containing your python files cd c:\path\to\python\folder
execute using python ex1.py where ex1.py is your filename
in the anaconda terminal

Related

How do you open Jupyter Notebook without Anaconda and from any directory?

I need help opening Python using the command line from other folders. Currently, I can only open Jupyter Notebook via the command line in the directory that Python was installed in. The following commands worked:
python -m jupyter notebook
or
python -m notebook
Excluding python -m or -m results in an error.
When trying to access python from any other folders using the same commands, I get the following error:
'python' is not recognized as an internal or external command,
operable program or batch file.
A similar error is thrown when I use jupyter notebook or notebook.
I have downloaded Python and have used it using IDLE. I also installed Jupyter Notebook using pip; I did this by accessing Windows Powershell in the folder where Python is located.
Would appreciate it also if someone could explain what was happening and what I could do in the future to avoid this. Thank you for the help!
Python is not recognised outside its own folder (as you mention). To 'expose' the Python command to the console, you can add it to your Windows environment variables, as per the Python documentation.
To permanently modify the default environment variables, click Start and search for ‘edit environment variables’, or open System properties, Advanced system settings and click the Environment Variables button. 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).
Concretely, in the environment variables of your system, edit the 'PATH' variable and add the folder with your Python executable to the path. After restarting your command prompt you should now be able to execute python commands.
While installing the Python, you can choose to add Python to PATH, if you check this while installing, you will have environment PATH variable in the machine.
Then you can just install notebook as you install any other packages/libraries in python.
pip install notebook
Once you do that, you should be able to start notebook from any folder/directory in your machine.
the command is pretty simple.
jupyter notebook

Problem executing "Pyinstaller" from command prompt

I am using cmd to install pyinstaller, the installation went fine but the moment I tried to turn a .py file to .exe an error appeared:
"pyinstaller" is not recognized as an internal or external command,
executable program or batch file.
This has never happened before.Thanks for helping.
Try,
python -m pyinstaller yourPythonFile.py

Launch pycharm from cmd in windows

I can't be able to launch pycham (community version) from the cmd. I also set up the environment variable but still, I am getting this- 'pycharm-community' is not recognized as an internal or external command,
operable program or batch file.
I have used all these commands - charm, charm., pycharm., pycharm. But, I am getting the same problem.
For MS windows:
Find where your pycharm is installed
If it is installed in C:\Program Files\JetBrains\PyCharm\
Type this in cmd:
setx PATH=%PATH%;C:\Program Files\JetBrains\PyCharm\bin
if not, then replace the path to where you pycharm is installed
setx PATH=%PATH%;C:\Path\to\your\pycharm\bin
If this doesn't work, try to restart you system once.
To start pycharm using command, first see what is the file name for executable for pycharm inside the bin folder and use that name. It can be pycharm.exe or something similar.
If it is pycharm.exe, use 'pycharm' in cmd to start it.

Problems executing jupyter notebook script from cmd in windows

First I added the 2 directory paths where I installed Anaconda3 in the Path system variable because I was getting this error:
'jupyter' is not recognized as an internal or external command.
i.e. 1. C:\ProgramData\Anaconda3
C:\ProgramData\Anaconda3\Scripts
However, I still cannot execute the script. I get a bunch of Tracebacks and the error at the end:
ImportError: DLL load failed: The specified module could not be found.
I am not sure where my script file needs to be but I tried 2 directories. First the initial directory where jupyter creates it and next I moved it inside the \Anaconda3\Scripts folder but both to no avail. I am also getting the same error if I try to run jupyter from cmd.
IPython notebooks are stored in .ipynb formats. While python files are of .py format. This being said, you'll have to convert the notebook to a python file.
cd into the directory your notebook exists and type the following in your command prompt
$ jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb
A .py file with the same name should now be there in the same directory.
You can find other export options available, and the examples mentioned in their docs

Trouble installing & starting Python from command line in Windows 7

I'm installing Python for use with SQLMap. I've downloaded and ran the Python 2.7.2 MSI installer, and restarted my computer. According to everything I've read, I should be able to just call python and SQLMap from the DOS command line using python sqlmap.py, but the command line doesnt seem to recognize the python - I get a 'python' is not recognized as an internal or external command,
operable program or batch file. error.
Do I need to add Python to my path variable? If so, how? Everything I've read says it should work out of the box...
Yes you should add it to your path. Does running C:\Python27\python.exe sqlmap.py work?
See for instance https://superuser.com/questions/143119/how-to-add-python-to-the-windows-path

Categories