Cannot open a python file in Ubuntu Terminal for Windows 10 - python-3.x

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.

Related

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.

Cytoscape and linux

Trying to install Cytoscape program on linux cytoscape. And I don't know how because first install button transfers me to HTML page and nothing is downloadable. (I have java installed). I tried to download tar.gz file but I am stuck, because there is no configure file and it says I have no permission for it. What should I do?
Once java 11 is installed on your computer try this:
ctrl+alt+T #open Ubuntu's console
cd /home/fulanita/Downloads #this is the directory where my computer has cytoscape.
chmod +x ./Cytoscape_3_8_1_unix.sh
./Cytoscape_3_8_1_unix.sh #3.8.1 is the last version for Ubuntu
the program will start to install
If anyone comes here in search for an answer I found a solution.
You go to you directory where you keep extracted tar.gz
with cd -Folderdestination/ you locate a folderwhere you keep a file named cytoscape.sh, and with command
sudo sh cytoscape.sh
install the program.

sudo ./sakis3g not found Python subprocess

I need subprocess in my script to connect with 3G. But unfurtunately it's throwing me alot of errors. So I was hoping maybe someone here could help me.
My code:
import subprocess
import time
subprocess.run('sudo ./sakis3g connect OTHER="USBMODEM" USBMODEM="12d1:1001" APN="internet"', shell=True)
When I run this simple script in my home directory I get the following error:
sudo: ./sakis3g: command not found
Is it maybe because the sakis3g script itself it located in /usr/local/bin. Any help would be appreciated, thanks in advance
I run this simple script in my home directory
./ means the current directory i.e. the home directory in this case.
Is it maybe because the sakis3g script itself it located in /usr/local/bin
/usr/local/bin is (likely) not your home directory. sudo can't find sakis3g in the current directory because there is no such file.
Use /usr/local/bin/sakis3g instead of ./sakis3g.
copy that saskis3g object file in your directory where you have your code then you can use the command directly without including any file path for the object file(i.e sakis3g) in your connect command.
if suppose you have a folder named sample. and your program resides in this folder then copy+paste the sakis3g object file to this folder[you can do this by using the CP command in linux ] and use the normal command ie " system("sudo ./sakis3g connect"); " no need of any path.

LXDE .desktop file permission issue

I’m trying to run a Python script via a desktop icon/shortcut/launcher on a Raspberry Pi using Raspbian and LXDE. I have to use a desktop launcher since the script has to be started via a tiny touchscreen only accepting left-clicks and without a keyboard.
I think that I have a permission issue since the script fails at a point where it should execute some system commands which require root.
The script works if I do the following:
Open a terminal
Enter sudo python3 program.py
I tried to replicate this behavior with a .desktop file using the following config:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Exec=sudo python3 program.py
Terminal=true
Icon=path/to/icon.png
Name=Program Launcher
I suppose I missed something obvious, but since I don’t work with Linux usually I’m a bit lost here.
Edit: The problem was not a missing permission but an incorrectly assumed working directory and is now solved. Sorry for my confusion.
In detail: during development the script was started from its own folder while the desktop launcher used /home/pi as working directory. In general that's not a problem, but in the script a hardcoded path was used and a required file not found when using the launcher. The real problem was sloppy swallowed and the status code of a permission issue returned. So it was simply a bad code issue.
As docs for desktop entries says:
The Exec key must contain a command line. A command line consists of
an executable program optionally followed by one or more arguments.
The executable program can either be specified with its full path or
with the name of the executable only. If no full path is provided the
executable is looked up in the $PATH environment variable used by the
desktop environment. The name or path of the executable program may
not contain the equal sign ("="). Arguments are separated by a space.
It leads to conclusion, that maybe python3 is not within $PATH used by the desktop environment. Try to check full path of your python3 and sudo with:
whereis python3
whereis sudo
on my Archlinux it gives me /usr/bin/python3 and /usr/bin/sudo. Try to modify your Dekstop entry to something like:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Exec=/usr/bin/sudo /usr/bin/python3 program.py
Terminal=true
Icon=path/to/icon.png
Name=Program Launcher
Let me know if this helps.

How to run .sh file from python program Ubuntu

I am trying to launch a .sh script from Python 3.3 in Ubuntu 13.10.
The script is supposed to shutdown the computer. I have already marked the sh script as executable through the terminal. I have tried to run the sh script through: os.system("script.sh"), subprocess.Popen("Script.sh"), and subprocess.call([script.sh]).
They keep returning the: OSError Exec format error.
Any help would be greatly appriciated!
I assume that script.sh isn't in your PATH but in your current working directory.
By default os.system and subprocess look in your path for the requested executable. So to execute something in your current working directory you need to specify the executable like this:
subprocess.call("./script.sh")
The ./simply says that the executable that should be executed is in the current working directory.

Resources