Running python script on ubuntu machine using ./myscript.py
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.
python main.py
Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.
./main.py
Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.
I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.
linux scripting python executable
add a comment |Â
up vote
3
down vote
favorite
I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.
python main.py
Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.
./main.py
Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.
I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.
linux scripting python executable
Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
â Jesse_b
Apr 28 at 20:12
@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
â GAURAV SRIVASTAVA
Apr 28 at 20:13
Does the python script you are getting errors with have a hashbang pointing to python?
â Jesse_b
Apr 28 at 20:14
@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
â GAURAV SRIVASTAVA
Apr 28 at 20:19
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.
python main.py
Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.
./main.py
Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.
I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.
linux scripting python executable
I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.
python main.py
Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.
./main.py
Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.
I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.
linux scripting python executable
edited Apr 29 at 12:49
Jeff Schaller
31.1k846105
31.1k846105
asked Apr 28 at 20:06
GAURAV SRIVASTAVA
185
185
Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
â Jesse_b
Apr 28 at 20:12
@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
â GAURAV SRIVASTAVA
Apr 28 at 20:13
Does the python script you are getting errors with have a hashbang pointing to python?
â Jesse_b
Apr 28 at 20:14
@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
â GAURAV SRIVASTAVA
Apr 28 at 20:19
add a comment |Â
Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
â Jesse_b
Apr 28 at 20:12
@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
â GAURAV SRIVASTAVA
Apr 28 at 20:13
Does the python script you are getting errors with have a hashbang pointing to python?
â Jesse_b
Apr 28 at 20:14
@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
â GAURAV SRIVASTAVA
Apr 28 at 20:19
Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
â Jesse_b
Apr 28 at 20:12
Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
â Jesse_b
Apr 28 at 20:12
@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
â GAURAV SRIVASTAVA
Apr 28 at 20:13
@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
â GAURAV SRIVASTAVA
Apr 28 at 20:13
Does the python script you are getting errors with have a hashbang pointing to python?
â Jesse_b
Apr 28 at 20:14
Does the python script you are getting errors with have a hashbang pointing to python?
â Jesse_b
Apr 28 at 20:14
@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
â GAURAV SRIVASTAVA
Apr 28 at 20:19
@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
â GAURAV SRIVASTAVA
Apr 28 at 20:19
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
./
is simply a relative path indicating the current working directory. When executing a file that is not in your PATH
it's necessary to prefix it with either the full path or a relative path, ./
is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py
The reason your python script gets errors when you execute it as:
./script.py
rather than:
python script.py
is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)
To get your script to execute properly using python add the following to the first line in the script:
#!/usr/bin/env python
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
./
is simply a relative path indicating the current working directory. When executing a file that is not in your PATH
it's necessary to prefix it with either the full path or a relative path, ./
is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py
The reason your python script gets errors when you execute it as:
./script.py
rather than:
python script.py
is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)
To get your script to execute properly using python add the following to the first line in the script:
#!/usr/bin/env python
add a comment |Â
up vote
1
down vote
accepted
./
is simply a relative path indicating the current working directory. When executing a file that is not in your PATH
it's necessary to prefix it with either the full path or a relative path, ./
is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py
The reason your python script gets errors when you execute it as:
./script.py
rather than:
python script.py
is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)
To get your script to execute properly using python add the following to the first line in the script:
#!/usr/bin/env python
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
./
is simply a relative path indicating the current working directory. When executing a file that is not in your PATH
it's necessary to prefix it with either the full path or a relative path, ./
is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py
The reason your python script gets errors when you execute it as:
./script.py
rather than:
python script.py
is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)
To get your script to execute properly using python add the following to the first line in the script:
#!/usr/bin/env python
./
is simply a relative path indicating the current working directory. When executing a file that is not in your PATH
it's necessary to prefix it with either the full path or a relative path, ./
is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py
The reason your python script gets errors when you execute it as:
./script.py
rather than:
python script.py
is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)
To get your script to execute properly using python add the following to the first line in the script:
#!/usr/bin/env python
answered Apr 28 at 20:24
Jesse_b
10.3k22658
10.3k22658
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440642%2frunning-python-script-on-ubuntu-machine-using-myscript-py%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
â Jesse_b
Apr 28 at 20:12
@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
â GAURAV SRIVASTAVA
Apr 28 at 20:13
Does the python script you are getting errors with have a hashbang pointing to python?
â Jesse_b
Apr 28 at 20:14
@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
â GAURAV SRIVASTAVA
Apr 28 at 20:19