Questions tagged [python]

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

Filter by
Sorted by
Tagged with
122
votes
9answers
264k views

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-...
11
votes
1answer
62k views

No such file or directory but I can see it!

I'm trying to run a python script, on a headless Raspberry PI using winSCP and get the following error message: Command '"./areadetect_movie_21.py"' failed with return code 127 and error message /usr/...
6
votes
1answer
12k views

Output of a python script running as unit is out of order while shells seems unnafected

How would I get all outputs of systemd managed python2 script instantly into journal, just like it appears in terminal I'm on centos 7, but seems to be same on arch according to systemd manual, ...
70
votes
4answers
131k views

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 ...
236
votes
9answers
576k views

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 ...
24
votes
2answers
96k views

Running Python on ChromeOS

Is it possible to run the Python interpreter on a ChromeOS machine? I've found various editors you can use, but I would like the ability to run python applications as well. I would like to purchase ...
4
votes
2answers
4k views

stderr gets flushed before stdout, when using file logger

My python code: import sys print "i am a daemon" print "i will be run using nohup" sys.stderr.write("i am an error message inside nohup process\n") When i run the code as python a.py, it shows, i ...
71
votes
3answers
44k views

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 ...
25
votes
1answer
21k views

How to run a command inside a virtualenv using systemd

I believe this should be simple but I can't get it to work properly. These are the commands I can run on command line: cd /home/debian/ap # Start a virtualenv source venv-ap/bin/activate # This ...
18
votes
5answers
9k views

How can I have more than one possibility in a script's shebang line?

I'm in a bit of an interesting situation where I have a Python script that can theoretically be run by a variety of users with a variety of environments (and PATHs) and on a variety of Linux systems. ...
3
votes
2answers
12k views

The python command starts the the wrong version of the python interpreter

I am using Mac OS X Version 10.13.1 and I have just installed anaconda. I have created a virtual environment using the command conda create -n py3 python=3 Then, I have started the python ...
15
votes
4answers
83k views

How to include python script inside a bash script

I need to include below python script inside a bash script. If the bash script end success, I need to execute the below script: #!/usr/bin/python from smtplib import SMTP import datetime ...
13
votes
2answers
6k views

Best way to upgrade vim/gvim to 7.3 in Ubuntu 10.04?

I have to use Ubuntu 10.04 at work, and can't upgrade it. I'm using Vim/gVim 7.2. I want to upgrade it to 7.3 (with Python and Ruby extension support). Which is the best way? Add an entry in sources....
6
votes
1answer
22k views

NFS mount: Device or resource busy

I referred the following link, the solution works. How to get over "device or resource busy"? The above solution works when you are manually deleting the file. But I have a python script ...
8
votes
1answer
5k views

Systemd Python service not sending all output to syslog

I have a custom service and have explicitly called for all stdout & stderr to be sent to syslog in the config file, however only some of the output appears in both syslog and the journal (they are ...
1
vote
2answers
7k views

Set Path for all Users (Login and Non-login Shells)

Ok. So, I'm used to Ubuntu and CentOS more than redhat, so I'm hoping there's some obvious solution to this that I'm missing. I've installed Anaconda (Python). I've placed it in: /opt/anaconda3 I ...
1
vote
1answer
1k views

Saving process output to a file in systemd unit file

I created a systemd file unit (Centos 7) and I wanted to save the Python output to a file but the service won't start with the below code. [root@static ~]# cat /etc/systemd/system/pykms.service [Unit]...
77
votes
6answers
634k views

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/...
70
votes
6answers
131k views

Using jq to extract values and format in CSV

I have the below JSON file: { "data": [ { "displayName": "First Name", "rank": 1, "value": "VALUE" }, { "displayName": "Last Name", "rank": 2, ...
35
votes
3answers
189k views

How to install the latest Python version on Debian separately or upgrade?

I'm still new to Linux, so I'm still trying to understand where executables and their libraries are and how to install packages, so I have Debian Wheezy 7.3 which has these Python versions: Python 2....
25
votes
5answers
35k views

What is the proper way to manage multiple python versions?

I have a machine with Python 2.6 installed as the default Python. Then, I installed Python 2.7, and manually created /usr/bin/python as a symlink to the new installation. Then, I was running into ...
26
votes
5answers
5k views

Pip vs Package Manager for handling Python Packages

Python packages are frequently hosted in many distribution's repositories. After reading this tutorial, specifically the section titled "Do you really want to do this" I have avoided using pip and ...
20
votes
8answers
71k views

Parse JSON using Python?

I have a JSON file members.json as below. { "took": 670, "timed_out": false, "_shards": { "total": 8, "successful": 8, "failed": 0 }, "hits": { "total": 74, ...
13
votes
4answers
12k views

How can I replace bash with Python?

According to the accepted answer for this SO question: , Python can make a great bash replacement. My question then, is this: how do I go about making a seamless switch? I think the main thing to ...
19
votes
6answers
38k views

Why is this python error message generated whenever I type a nonsense command?

Whenever I type any "nonsense" command, this python error message is generated. Normal commands work fine. Any idea how to debug this? $ somenonexistingcommand Traceback (most recent call last): ...
16
votes
8answers
16k views

How can I rename photos, given the EXIF data?

Let's say I have a bunch of photos, all with correct EXIF information, and the photos are randomly named (because of a problem I had). I have a little program called jhead which gives me the below ...
8
votes
4answers
11k views

Sending the output from 'dd' to awk/sed/grep

I'm trying to approximate the computer's write speed using dd: dd if=/dev/urandom of=/dev/null bs=1K count=10000 which gives the following output 10000+0 records in 10000+0 records out 10240000 ...
14
votes
4answers
71k views

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 ...
7
votes
3answers
20k views

'ImportError: No module named _struct' error when managing packages

I'm running elementary OS 0.2 (based on Ubuntu 12.04) and starting today I'm seeing a weird error when attempting to install/upgrade packages. Just now for example I did a: sudo apt-get update which ...
4
votes
1answer
4k views

Remote installation of pip from python3 without root

I'm trying to install python3 for one of remote hosting over ssh. I don't have root access. Installation was done with: wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz tar xvzf Python-3....
1
vote
3answers
4k views

How to install easy_install using non-default Python Interpreter on CentOS?

I have downloaded, compiled and installed Python 2.7 on CentOS. I would like to download and install easy_install (and pip) for it but I am a little bit confused as to how to do that. How can I ...
4
votes
3answers
10k views

Delete XML node containing certain element

I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed: <Placemark> <styleUrl>#m_ylw-pushpin330</...
4
votes
1answer
811 views

is 'sed' thread safe

If I have a shell/python script that uses sed to modify a file in place based on user inputs, and then two users run the same script at the same time or approx. same time, is 'sed' thread safe ? Or ...
4
votes
4answers
142 views

I want to terminate a python script if it doesn’t output anything to the terminal in 2 min

Here's my current bash which is just a loop while true ; do python3 /Users/Name/Desktop/pythoncode.py done I want to terminate pythoncode.py if it doesn’t output anything to the terminal in 2 ...
2
votes
2answers
1k views

python2 and OpenSSL don't play together on Kali - how to fix?

I have a Kali Linux distrubution which is Kali GNU/Linux Rolling (currently version 2017.3) on amd64. I'm keeping it regularly up to date and have not meddled with system files or the package ...
2
votes
0answers
537 views

apt-get update no longer works after rebuilding corrupted PATH variable

I royally screwed up my PATH variable last night, thankfully a user called Icarus helped me rebuild it here. However it's not fully fixed and I receive the same (or maybe very similar) error that I ...
2
votes
1answer
9k views

Linux Mint 13 Problem - No module named site

My Linux Mint 13 64-bit system has developed a problem. Whilst I can run basic commands like ls and vi if I try anything more complex (I have tried python2.7, mysql-workbench and adduser) I get:- ...
1
vote
2answers
1k views

Random files selector in filesystem

Context : In order to test some backup process which are supposed to work all nights, i want to select a random files on a large amount of datas. (Around 7 millions of files. This is a NFS server with ...
1
vote
2answers
3k views

Sudo apt-get remove python, gnome did not boot, tried dpkg --unpack *.deb

This happened after last night I was stubborn and sleepy enough to not read that it's best to install the missing dependencies from the var/logs and was lazy enough to just Google and try the first (...
0
votes
1answer
221 views

Making a text based server with netcat or other programs? [closed]

The idea I have is to make a netcat server, and when you connect to it, the server runs a python script with which the user can interact. So for example the script asks for a number, and it outputs ...
0
votes
1answer
502 views

Pass bash variable into python file

I have a Python script that I want to pass a bash variable to. bash.sh while read -r db do Printf "%s\n" ${db} "Found" done < path/to/file.txt output: db1 db2 db3 file.txt ...
0
votes
1answer
60 views

Select every two rows if they begin with the same name

I have a table that looks like this: name something 1 100036498|F|0--20:T>G something 2 100036501|F|0--44:C>T something 3 ...
0
votes
1answer
3k views

'setenv' command not working on tcsh shell when called explicitly

I can run setenv command just fine in my tcsh shell like this: echo $0 /usr/bin/tcsh echo $SHELL /usr/bin/tcsh setenv START_TIME `date +%s` echo $START_TIME 1499355967 But, whenever I run it ...
-1
votes
1answer
775 views

How to schedule a cron job to run a video fill every 5 minute?

I need to play a video file on vlc every 5 minutes daily.
39
votes
11answers
107k views

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 ...
22
votes
3answers
4k views

Why is coreutils sort slower than Python?

I wrote the following script to test the speed of Python's sort functionality: from sys import stdin, stdout lines = list(stdin) lines.sort() stdout.writelines(lines) I then compared this to the ...
22
votes
7answers
25k views

Why does my Python background process end when SSH session is terminated?

I have a bash script that starts up a python3 script (let's call it startup.sh), with the key line: nohup python3 -u <script> & When I ssh in directly and call this script, the python ...
19
votes
4answers
42k views

How to make python3.7 default

I have installed python3.7 however I am not sure how to make it the default python. See below: ~/Documents/robosuite$ python3.7 Python 3.7.1 (default, Oct 22 2018, 11:21:55) [GCC 8.2.0] on linux ...
11
votes
4answers
17k views

Hybrid code in shell scripts. Sharing variables

This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
21
votes
5answers
25k views

Using different versions of Python

Background: Since I develop python programs that must run on different python versions, I have installed different versions of python on my computer. I am using FC 13 so it came with python 2.6 pre-...