Questions tagged [python]

Python is an interpreted programming language that is often, but not solely, used as a scripting language. A version of Python is included by default on all Ubuntu distributions.

Python is a general purpose language which can be used for anything from quick scripting jobs to fully object-oriented GUI programs.

Python is designed to have readable source code. As such, code blocks are delimited by indentation instead of the braces used in many other languages. Python is one of few programming languages to have significant white space.

Unlike C-like languages, Python is generally not compiled and is instead an interpreted language. The most common interpreter is CPython, which is written in C. Other interpreters are PyPy, which is written in Python and Jython, which is written in Java.

From http://hg.python.org/peps/rev/76d43e52d978 (PEP 373, Python 2.7 Release Schedule):

The End Of Life date (EOL, sunset date) for Python 2.7 has been moved five years into the future, to 2020. This decision was made to clarify the status of Python 2.7 and relieve worries for those users who cannot yet migrate to Python 3.

5111 questions
685
votes
8 answers

How to make 'python' program command execute Python 3?

The python program command executes Python 2. Python 3 can be executed using the python3 command. How can Python 3 be executed using the python command?
Giri
  • 6,993
  • 3
  • 13
  • 9
224
votes
11 answers

How do I install a different Python version using apt-get?

How can I install a different version of Python using apt-get? Obviously I realise I can install using the source tar ball, however I would prefer not to install from source and instead use the package manager, as that's what it's there for. Surely…
AgileZebra
  • 2,343
  • 2
  • 10
  • 7
192
votes
19 answers

ModuleNotFoundError: No module named 'distutils.util'

After updating to Ubuntu 20.04, whenever I run: pip install or pip --version it says: adam@daryy:~$ pip3 Traceback (most recent call last): File "/usr/local/bin/pip3", line 5, in from pip._internal.cli.main import…
Rock Life
  • 2,020
  • 2
  • 6
  • 4
188
votes
6 answers

How do I install the latest Python 2.7.X or 3.X on Ubuntu?

I want to install the latest Python tarball on Ubuntu, downloaded from http://python.org/download/. Is this is a correct way to install? ./configure make make install If not, how do I do that?
mohammads
  • 2,682
  • 2
  • 18
  • 23
162
votes
8 answers

Pip is not working: ImportError: No module named 'pip._internal'

Running pip or pip3 results with: Traceback (most recent call last): File "/home/myuser/.local/bin/pip", line 7, in from pip._internal import main ImportError: No module named 'pip._internal' I had issues with this, and uninstalled pip3,…
Keweik
  • 1,721
  • 2
  • 8
  • 8
129
votes
4 answers

apt-get install vs pip install

I am a bit confused about the cases in which the above commands must be used when downloading python packages. I was trying to download a package named pyudev in accordance with an answer with this question. I executed this command : sudo pip…
Vineet Kaushik
  • 2,154
  • 7
  • 25
  • 35
125
votes
3 answers

installing pip3 (for python3) on ubuntu 16.04 LTS using a proxy

I have tried entering: sudo apt install python3-pip The error I get is: $ sudo apt install python3-pip Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be…
Abisdad
  • 1,351
  • 2
  • 8
  • 4
123
votes
5 answers

How do I sudo a command in a script without being asked for a password?

I want to turn my system on automatically every day. So I use the below code in my Python script, but sudo asks me for a password every time: os.system('sudo sh -c "echo date \'+%s\' -d \'+ \ 24 hours\' > /sys/class/rtc/rtc0/wakealarm"') How…
Viswa
  • 1,649
  • 4
  • 15
  • 15
120
votes
15 answers

How do I check whether a module is installed in Python, and install it if needed?

In terminal, after I start Python, how will I know what are the modules present in python? Suppose I need to learn the modules NumPy and SciPy. How will I install it if it is not installed? How will I know if it is already installed?
sigdelsanjog
  • 7,010
  • 17
  • 41
  • 70
117
votes
3 answers

How to add a Python module to syspath?

I have a file structure like this: Folder Common foo1.py TestFolder foo2.py I want to import in foo2.py and foo1.py. I tried but it doesn't work on Ubuntu: sys.path.append(os.path.abspath('../../')) from Common import foo1.py
user284474
  • 1,171
  • 2
  • 8
  • 3
115
votes
6 answers

How to install geckodriver in Ubuntu?

I use Selenium in Python, I tried to run the webdriver function: default_browser = webdriver.Firefox() This Exception: WebDriverException: Message: 'geckodriver' executable needs to be in PATH. geckodriver in this site:…
mySun
  • 1,933
  • 4
  • 13
  • 17
111
votes
9 answers

Is there a GUI designer for Python?

Is there a GUI IDE for programming Python just like Java has NetBeans? I wanted one where we could drag & drop test boxes & labels just as we do with Swing components using NetBeans or Eclipse. Or is there an add-on present in either NetBeans or…
Roshan
  • 1,203
  • 2
  • 11
  • 9
105
votes
11 answers

How to install Anaconda on Ubuntu?

How to install Anaconda for Python on Ubuntu? Is there a way to use apt-get install? I only have command line access to my server. How do I install Anaconda on Ubuntu 14.04 from the command line?
alvas
  • 2,867
  • 10
  • 34
  • 47
102
votes
9 answers

What version of Python do I have?

How can I find out what versions of Python I have? I am using Ubuntu 14.04 (Trusty Tahr).
sigdelsanjog
  • 7,010
  • 17
  • 41
  • 70
98
votes
10 answers

How can I upgrade pip to the latest version?

I installed pip using get-pip.py, but the following error happened after pip freeze gets executed: Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main …
Raja Simon
  • 1,379
  • 2
  • 12
  • 15
1
2 3
99 100