How to change Linux terminal idle default version [duplicate] - python

This question already has answers here:
Python IDLE: Change Python Version
(6 answers)
Closed 4 years ago.
Please I installed Idle3. But when I launched it by typing Idle from the terminal, it loaded python3.6.6 by default. If I search Idle under applications
There are three options:
Idle
Idle using python 3.6.6
Idle using python 3.7.0
My question is: Is it possible to change the default idle that opens when I type Idle from terminal?
Thank you

This question is a possible duplicate of Python IDLE:Change Python Version`
But in any case. Here's what you can do:
In your terminal type
sudo nano /usr/bin/idle-python3.6.6
The first line should look something like this
/usr/bin/python3.6.6
Change the end of the line to the version you are looking for idle to open by defauly (3.7.0 in your case).
Hope that helps:) oh and welcome to stackoverflow

If you do:
which idle
You get the path which is used for running idle, e.g. /usr/bin/idle
I'm guessing a bit but I think that it might be a soft link that points to the 3.6.6 version of idle. If so, you can see where the soft link points by doing
ls -l /usr/bin/idle
That would return something like "/usr/bin/idle -> /usr/bin/idle3.6.6"
To update the soft link, use ln with -f:
ln -s -f /usr/bin/idle3.7.0 /usr/bin/idle
And that should hopefully update the link to use the later version. Do note that I have assumed the /usr/bin path for the executables, it might be different in your case.

Related

Creating a scikit-learn contribution package [duplicate]

This question already has answers here:
What does the $ mean when running commands?
(5 answers)
Closed 7 years ago.
As a beginner in Python, I'm reading a book written by Bill Lubanovic
I found something weird.
In that book, After saving simple code in test1.py, which is
print("This standalone program works!")
it says python can run it by typing in
$ python test1.py
However, whenever I try to use that, syntax error happens.
Although I know there are other methods like using exec() which I found in this website, I wanna know why book uses that method which doesn't work at least for me.
It means you need to type everything but the $ in the terminal.
python test1.py
It's just a convention though. Authors also use > python test1.py and other notations.
I don't know which version of his book you're reading, but he mentions it in this version.
In the example that follows, $ is a sample system prompt for you to type a command like python in the terminal window. We’ll use it for the code examples in this book, although your prompt might be different.
You are not supposed to enter the $.
The $ represents the shell/terminal prompt. This is the string of characters that appear in your terminal when it is waiting for input, although $ typically indicates some flavour of unix, e.g. linux.
Your terminal will probably use a different prompt, e.g.
[user#localhost ~]$
Or, if you are using a Windows terminal you might see :
C:\>
or
C:\WINDOWS>
Question was answered in following stackoverflow post:
What does the $ mean when running commands?
What does the $ mean when running commands?
As of now, Python does not implement $ in its syntax. So, it has nothing to do with Python.
Instead, what you are seeing is the terminal prompt of a Unix-based system (Mac, Linux, etc.)
So basically is terminal prompt and you should type in only: python test1.py without $ sign. another example is ~ when using oh-my-zsh.

How would I go about making a Python script into an executable? [duplicate]

This question already has answers here:
Set up Python on Windows to not type "python" in cmd
(4 answers)
How to make python scripts executable on Windows? [duplicate]
(1 answer)
Closed 5 years ago.
I'm reading from a "bookazine" which I purchased from WHSmiths today and its said
during the setup I need to type in these commands into the terminal (or the Command Prompt in my case) in order to make a script without needing to do it manually. One of these commands is chmod +x (file name) but because this is based of Linux or Mac and I am on Windows I am not sure how to make my script executable, how do I?
Thanks in advance.
In the Python documentation there is a small excerpt on this.
On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to make scripts executable from the command prompt as ‘foo.py’. If you’d rather be able to execute the script by simple typing ‘foo’ with no extension you need to add .py to the PATHEXT environment variable.
https://docs.python.org/2/faq/windows.html
Aside from that, like cricket_007 said, you can execute your scripts as
C:\User\YourName> python yourscript.py
You don't have shell scripts on Windows, you have batch or powershell.
If your reading is teaching Unix things, get a virtual machine running (insert popular Linux distribution here).
Regarding python, you just execute python script.py

How to tell, from within a running script, what Python interpreter is running it? [duplicate]

This question already has answers here:
Find full path of the Python interpreter?
(3 answers)
Closed 6 years ago.
I would like to output, in my script, the full path of the Python interpreter running it:
#!/usr/bin/env python
print("{}".format(full_path_of_interpreter_running_this_script)
The script is in the PATH and run as:
script.py
Can I do that? How?
Note: Doing which python or type python in bash does not help me, because I am using pyenv, and pyenv is doing shims magic.
Note: More than identifying the Python executable, I am interested in identifying the virtualenv that is being used, and I thought knowing the full path to the interpreter will help me in this.
This gives the full path to the command that was used to run the script:
import sys
print(sys.executable)

What is '$' in python? [duplicate]

This question already has answers here:
What does the $ mean when running commands?
(5 answers)
Closed 7 years ago.
As a beginner in Python, I'm reading a book written by Bill Lubanovic
I found something weird.
In that book, After saving simple code in test1.py, which is
print("This standalone program works!")
it says python can run it by typing in
$ python test1.py
However, whenever I try to use that, syntax error happens.
Although I know there are other methods like using exec() which I found in this website, I wanna know why book uses that method which doesn't work at least for me.
It means you need to type everything but the $ in the terminal.
python test1.py
It's just a convention though. Authors also use > python test1.py and other notations.
I don't know which version of his book you're reading, but he mentions it in this version.
In the example that follows, $ is a sample system prompt for you to type a command like python in the terminal window. We’ll use it for the code examples in this book, although your prompt might be different.
You are not supposed to enter the $.
The $ represents the shell/terminal prompt. This is the string of characters that appear in your terminal when it is waiting for input, although $ typically indicates some flavour of unix, e.g. linux.
Your terminal will probably use a different prompt, e.g.
[user#localhost ~]$
Or, if you are using a Windows terminal you might see :
C:\>
or
C:\WINDOWS>
Question was answered in following stackoverflow post:
What does the $ mean when running commands?
What does the $ mean when running commands?
As of now, Python does not implement $ in its syntax. So, it has nothing to do with Python.
Instead, what you are seeing is the terminal prompt of a Unix-based system (Mac, Linux, etc.)
So basically is terminal prompt and you should type in only: python test1.py without $ sign. another example is ~ when using oh-my-zsh.

Python can't execute terminal script, using sh nor bash [duplicate]

This question already has answers here:
Can I use an alias to execute a program from a python script
(5 answers)
Closed 8 years ago.
i hope you guys can help me with this problem because i'm really stuck... I'm trying to execute a program from python and, for some reason, it doesn't work. The script is located at:
path/to/teqc
I've added this line to the .bashrc file:
alias teqc='path/to/teqc'
and, when i run
teqc -tr d input >output
on a terminal it works fine... but, if i run it on a python program, it shows:
sh: teqc: command not found
the code i've been using on python is:
os.system('teqc -tr d input >output')
I tried using
subprocess.Popen('teqc -tr d input >output', shell=True, executable="/bin/bash")
but the only result was to change the error message to
/bin/bash: teqc: command not found
Any help would be really appreciated :)
P.D. I forgot to specify, the operating system is Fedora 21
I would suggest creating a symbolic link to your program .
ln -s /path/to/teqc /usr/bin/teqc
I think the problem is that the environment variable PATH is not the same when you run the command in the code using subprocess.
One solution would be to have a soft link in as suggested in the previous answer
Other thing you can do is to have your code set the environment before you execute your command using subprocess the os module comes has a os.environ dictionary which can be used to append the path using something like this
import os
import subprocess
os.environ['PATH'] += ":/path/to/teqc"
subprocess.Popen(['teqc -tr d input'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)

Categories