Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

For more information please see the official website. Note that programming questions might be more fit for Stack Overflow unless they are specifically UNIX-related.

2270 questions
346
votes
10 answers

Change the Python3 default version in Ubuntu

I am using Ubuntu 16.04 LTS . I have python3 installed. There are two versions installed, python 3.4.3 and python 3.6 . Whenever I use python3 command, it takes python 3.4.3 by default. I want to use python 3.6 with python3. python3 --version shows…
codeclue
  • 3,573
  • 3
  • 9
  • 6
126
votes
9 answers

How to install Python 3.6?

I'd like to install the latest Python, which is 3.6 at the time of this post. However, the repository is saying that Python 3.4.2 is the newest version. I've tried: $ sudo apt-get update $ sudo apt-get install python3 python3 is already the newest…
davidtgq
  • 1,494
  • 2
  • 10
  • 10
125
votes
2 answers

How can I start the python SimpleHTTPServer on port 80?

I am using this command on Ubuntu but it is starting on port 8080 and I don't have another server running so I'd like it to start on port 80. I saw ways that you could set up a bash script to do something like this, but isn't there a command line…
cwd
  • 44,479
  • 71
  • 146
  • 167
109
votes
6 answers

zipimport.ZipImportError: can't decompress data; zlib not available

On RHEL 6.6, I installed Python 3.5.1 from source. I am trying to install pip3 via get-pip.py, but I get Traceback (most recent call last): File "get-pip.py", line 19177, in main() File "get-pip.py", line 194, in main …
Flair
  • 1,191
  • 2
  • 7
  • 6
97
votes
8 answers

How do you list number of lines of every file in a directory in human readable format.

I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know How many lines are in each file. How many lines are in directory. How many…
Hexatonic
  • 1,215
  • 2
  • 10
  • 9
92
votes
6 answers

Execute shell commands in Python

I'm currently studying penetration testing and Python programming. I just want to know how I would go about executing a Linux command in Python. The commands I want to execute are: echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A PREROUTING…
Xanmashi
  • 1,053
  • 1
  • 8
  • 10
82
votes
3 answers

How does /usr/bin/env know which program to use?

When I use the shebang #!/usr/bin/env python to run a script, how does the system know which python to use? if I look for a python bin path in the environment variables I find nothing. env | grep -i python
tMC
  • 1,175
  • 1
  • 9
  • 12
79
votes
4 answers

Write Python stdout to file immediately

When trying to write the stdout from a Python script to a text file (python script.py > log), the text file is created when the command is started, but the actual content isn't written until the Python script finishes. For example: script.py: import…
Bart
  • 890
  • 1
  • 7
  • 9
54
votes
5 answers

Recommended way of installing python packages on Arch

What's the recommended way of installing python packages on Arch? Searching for them on the AUR and installing them from there (or create a PKGBUILD file to make a package yourself) or using pip? I started off by installing stuff from pacman and the…
Nils Werner
  • 3,554
  • 2
  • 16
  • 14
50
votes
6 answers

How can I use environment variables in my shebang?

I have a Python script that need to be run with a particular python installation. Is there a way to craft a shebang so that it runs with $FOO/bar/MyCustomPython?
eric.frederich
  • 603
  • 1
  • 5
  • 5
44
votes
6 answers

systemd "status=203/EXEC" error when creating new service

I've created a new service for a Python script that works when running standalone but gives errors below when run through systemd : Oct 02 12:17:09 raspberrypi systemd[1]: Started Read pressure And Post to mqtt. Oct 02 12:17:09 raspberrypi…
resolver101
  • 561
  • 1
  • 5
  • 7
42
votes
12 answers

How to restart the Python script automatically if it is killed or dies

I am running my Python script in the background in my Ubuntu machine (12.04) like this - nohup python testing.py > test.out & Now, it might be possible that at some stage my above Python script can die for whatever reason. So I am thinking to have…
arsenal
  • 3,053
  • 17
  • 44
  • 49
40
votes
16 answers

Converting CSV to TSV

I have a number of large CSV files and would like them in TSV (tab separated format). The complication is that there are commas in the fields of the CSV file, eg: A,,C,"D,E,F","G",I,"K,L,M",Z Expected output: A C D,E,F G I K,L,M …
user14755
40
votes
4 answers

uninstall Python installed by compiling source?

I installed Python 2.7.9 on Ubuntu 14.04 by compiling its source, by .configre, make, and make altinstall. make altinstall is because I don't want to overwrite the default Python 2.7.6. My self installed 2.7.9 is in /usr/local/bin/python2.7 and many…
Tim
  • 98,580
  • 191
  • 570
  • 977
36
votes
6 answers

How do I make python programs behave like proper unix tools?

I have a few Python scripts laying around, and I'm working on rewriting them. I have the same problem with all of them. It's not obvious to me how to write the programs so that they behave like proper unix tools. Because this $ cat characters |…
ixtmixilix
  • 13,040
  • 27
  • 82
  • 118
1
2 3
99 100