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.

2338 questions
379
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,903
131
votes
3 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
  • 47,367
125
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,504
114
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 <module> main() File "get-pip.py", line 194, in main…
Flair
  • 1,241
109
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 lines…
Hexatonic
  • 1,335
  • 3
  • 10
  • 9
96
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,093
  • 1
  • 8
  • 10
85
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,205
83
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:…
Bart
  • 930
61
votes
7 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…
Nils Werner
  • 3,824
54
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…
52
votes
5 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…
Tim
  • 107,810
51
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 ?
43
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,113
41
votes
17 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 Z (where whitespace…
user14755
40
votes
4 answers

Replace multiline string in files

I have a number of files I want to update by replacing one multi-line string with another multi-line string. Something along the lines of: * Some text, * something else * another thing And I want to replace it with: * This is completely * different…
ventsyv
  • 1,079
1
2 3
…
99 100