connecting python to the command prompt - python-3.x

I'm watching a video on YouTube that that is telling me to type cd documents and then within that file type cd python to connect python, but every time I try this it says "the system cannot find the path specified" I don't understand why it is saying this because I can see that python is in my documents folder.

If you are using Windows CMD or Powershell, use the command py instead of python.
Example: py myscript.py (or py.exe .\myscript.py also works)

if you want to run the python code which is located in your documents folder then open cmd and type "cd documents" and if your python code is in same folder then type "python 'filename'.py" pre enter to run

Related

can someone help me get python to run my scripts in CMD in windows 10 without having to cd to exact path each time.?

I'm trying to get python to run my scripts via CMD line.
note: idr if the book said where (a specific place to store my files for) python to access them but scanning back over the beginning I didn't find any relation to it.
According to this book https://automatetheboringstuff.com/2e/appendixb/ I am supposed to be able to type python (script.py) in command line just like this and it should run the script:
Here's the error I am getting upon execution, compared to the example from the book below it to show that this is supposed to work.
CMD LINE OUTPUT :
Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Armagon>python conway.py
python: can't open file 'conway.py': [Errno 2] No such file or directory
C:\Users\Armagon>
As you can see I get a python Error and researching this has given me nothing I found useful.
Here is the exact sample quoted from the book:
Microsoft Windows [Version 10.0.17134.648]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\Al>python hello.py
Hello, world!
C:\Users\Al>
First off, doing some research I have found a way to make it work, by cd(change directory) to the direct path of the folder containing the scripts C:\Users\Armagon\Desktop\mystuff. This helps to verify that the script I am trying to run is in fact located there and I've spelled it correctly.
But, according to everything I've followed up to this point I shouldn't have to do it this way.
The scripts are on my desktop all in the same folder called mystuff.
Following this link as well as a video Add a directory to Python sys.path so that it's included each time I use Python
I added the mystuff folder to PYTHONPATH in environment variables exactly as suggested. Here is a partial output of the sys.path (ran from IDLE) that shows mystuff filepath is added, so I'm pretty sure I did that part right.
['', 'C:\\Program Files\\Python38\\Lib\\idlelib', 'C:\\Users\\Armagon\\Desktop\\mystuff']
Maybe I've confused what is supposed to be happening here
I am operating under the assumption (based off what I've learned so far) that when CMD executes the line: python (script).py
It's supposed to run python.
Which in turn python is supposed to find my scripts on desktop (by the PYTHONPATH environment variable I created) and execute the script typed in CMD.
I've tried a lot of things in the process of getting just this far. I'd really appreciate if someone could point out what it is I'm overlooking to run python scripts from my desktop just like the book. I'm not very skilled at present and will gladly add any information as needed if I have excluded pertinent info I apologize in advance.
You should be able to do this as long as the script is in the module search path, for example, the PYTHONPATH environment variable. You should then be able to run the script like this:
python -m script
Well, the cd way is the way to go to run a python file via the command prompt. There is no other way I can think of.
Follow these steps or this link -> https://www.wikihow.com/Use-Windows-Command-Prompt-to-Run-a-Python-File to do it:
1)Open command prompt. type cmd or command prompt in search bar or run and press enter key.
2)In command prompt, given that the folder you are trying to access is in desktop, type-> cd desktop\myStuff.. Press enter.
3)Just write- python filename.py and enter.
4)It should run automatically.

Open terminal in XFCE from script and activate python virtualenv

I try to open terminal in XFCE and activate python3 virtualenv using the following line in a bash script:
xfce4-terminal --working-directory=$HOME/path/to/project --maximize \
-e 'bash -c "source $HOME/path/to/project/venv/bin/activate; bash"'
The strange thing is that the virtualenv gets kind of activated since:
which python
shows the correct path to the virtualenv directory and the project seems to be working fine.
However I don't see the (venv) to the left from the shell prompt. Moreover, when I enter deactivate it complains that no such command can be found.
Is there a proper way to solve this problem?
I created a bash shortcut for this in my /Users/username/.bash_profile (I use mac; on linux use Users/username/.bashrc instead).
function pcd() {
cd /Users/username/Code/"$1"_env/"$1"
source ../env/bin/activate
atom -a .
}
Where project_env is the root folder, which contains the venv, and the project folders (project folder is where code goes)
to execute this simply call pcd project
I don't know much about bash, so I can't really tell you why your code doesn't work.
Also, make sure you open a new terminal window after saving this.

I can't open a python file in git bash

I'm trying to open a .py file on git bash but it doesn't work.
I have tried to follow some instructions like running python <filename> but it doesn't work for me.
When I run
python python_basics
I expect it will open the .py file but it says it can't open file 'python_basics':
[Errno 2] No such file or directory
From this question, the problem may very well be caused by Git Bash itself.
I would recommend you try running your Python file from a different terminal (Command Prompt or PowerShell if you are using Windows), using the command suggested in the comments:
python python_basics.py
Thank you for your question, I am here to help you and who will see this question.
if you mean you want to open the file like when click on the file and open it
you can use this command
Start filename.py
but if you want to open the file inside the gitbash use this command
vim filename.py
and if you mean to run the file from gitbash you can use this command
python pythonFileName.py
Now if the above command did not work with you, and you are in the windows10 Pro platform you should go to
environment variable >> Then system variable >> then choose path >> then Edit >> and put the python path >> restart the terminal and run it again
Notice: All of the above I tried and used in windows10 pro.
Thanks,
Hope to help anyone,
First check the python version installed on your system.
by command-
python --version.
If not found
set
$ PATH=$PATH:/c/Python27/
Adapting the path will solve your problem.

How to run python by Notepad++

I want to script with python using Notepad ++ but it works strangely, actually it does not work, so I have pycharm an everything is going well but in notepad ++ when I save file with .py and click run it does not work is there a step by step instruction to follow?
I have same problem with sublime text editor so I am lucky with just Pycharm all of the others has confused me please help me.
Notepad++ and sublime are text-editors and not interpreters. To run python script, you need a python interpreter. If you want to use notepad++, then write the python script in notepad++, open command prompt and run the python script from command prompt.
Assuming that you have python installrd, suppose you have created a file name "example.py" in the path "C:/Users/User/Desktop", then to run the script you will have to run the following commands:
$ cd "C:/Users/User/Desktop"
$ python example.py
I have no idea Why you gave me this -1 may be someone think that he knows everything so my idle.py is not the same location to my computer and when I assign location it pops up an error
sorry for error message image it is unable to copy

running py3to2 using windows 7

I've tried my best for an hour, but I just don't understand code lingo well enough to get py3to2 to work. I have a script written in Python 3 that I want to convert to 2. Downloaded and unzipped py3to2 from here:
https://bitbucket.org/amentajo/lib3to2/overview
This is all the read me says about running it:
Usage
Run "./3to2" to convert stdin ("-"), files or directories given as
arguments. By default, the tool outputs a unified diff-formatted patch on
standard output and a "what was changed" summary on standard error, but the
"-w" option can be given to write back converted files, creating
".bak"-named backup files.
If you are root, you can also install with "./setup.py build" and
"./setup.py install" ("make install" does this for you).
Do I need to run Python? Command line? I'm lost. Has anyone done this? Thanks.
Do you know how to use pip?
Just type in C:/[Enter your python folder]/Scripts/pip install 3to2
Go to the Scripts folder in the Python folder and rename 3to2 to 3to2.py
Then, type in C:/[Enter python folder again]/python.exe C:/[Enter python folder]/Scripts/3to2.py -w Path/To/The/Python/File

Resources