I can't open a python file in git bash - python-3.x

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.

Related

Pumba installation - Command not found on linux terminal

I am trying to install pumba from the OS release page. Once it is downloaded, I try running
pumba --help
It gives a command not found error.
Can anyone suggest what am I missing? The amd_64 file has all read, write and execute permissions.
If the name of the file is pumba_linux_amd64, you have to use that. Additionally, since the file is (assuming) not in your $PATH, you can't launch it directly.
If your file is in your current directory, run
./pumba_linux_amd64

Trying to test Python on Win 10, getting Errno 2. Path to python is given to the value of env variable

I've installed Python 3.8 on Win 10 machine. Path to Python is C:\Users\userid\AppData\Local\Programs\Python\Python38\
Path environment variable values are: C:\Users\userid\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe
In order to test python, I created a simple script called "script.py" in directory C:\python_scripts.
Then I tried to run "script.py" from the directory where it is located, but got error:
C:\python_scripts> python script.py
C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'script.py': [Errno 2] No such file or directory
What might be the cause of getting this error? i tried to run the script with both cmd and powershell, with the usual user rights and with elevated admin rights, still getting Errno 2.
No other versions of Python have been previously installed on this machine (which is a corporate one, if that might be significant)
Thank you
Thank you #OferSadan for your suggestion to use dir command, it helped me to solve the problem. The "script.py" had an additional .txt extension added to it for some reason, but the Windows explorer only showed .py extension by default. Now I deleted the trailing .txt suffix and the script runs

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.

Cannot open a python file in Ubuntu Terminal for Windows 10

I'd like to open a python file (main.py) in my Ubuntu terminal for windows 10, how would I go about doing that? I've tried simply opening terminal and entering "python main.py" or "python3 main.py" but I get errno2 (no such file or directory).
I've tried changing the directory to C: to access the file, and I've tried doing python (filepath) of the file.
python3: can't open file 'main.py': [Errno 2] No such file or directory
I expected for main.py to be open and ran in Ubuntu terminal
It sounds like main.py isn't in the same directory you're currently in.
You may want to familiarize yourself with Bash, the shell which Ubuntu (and most Linux distributions) uses by default, and what you're likely using in your terminal.
To see the directory you're currently in, use pwd:
cball#cball:~$ pwd
/home/cball
To see what is in your current directory, use ls:
cball#cball:~$ ls
Desktop
Documents
Downloads
...
You can move into another directory cd directoryName:
cball#cball:~$ cd Desktop/
cball#cball:~/Desktop$ ls
cats.jpg
Here is a fairly gentle intro to linux: https://www.digitalocean.com/community/tutorials/an-introduction-to-linux-basics
Once you know where your Python file is, you can run python /path/to/main.py or simply python main.py if you are already in that directory (or if main.py is in your path variable).
Good luck learning bash, linux, and python! :) Please let me know if you have any questions.

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

Resources