Tag Info

New answers tagged

1

Simply start your command with sudo rights: sudo your_python_script And NEVER use your password in a parameter.


0

Firstly I don't know whether the logic is correct with my option, but it certainly works. First you create a rsa pub key using the command: ssh-keygen -t rsa Then copy and append the pub key to .ssh/authorized_keys of root by using the command: ssh-copy-id root@<your ip> After that when you try ssh root@<your ip>, it won't prompt for the ...


0

You are doing this far too complicated. If it's included in python3, just create it with : python3 -m virtualenv You can even create an alias if you wish to alias virtualenv3='python3 -m virtualenv' Depending on the machine, you might need to specify the interpreter: alias virtualenv3='python3 -m virtualenv -p python3'


3

Another usage of xclip The solution below uses xclip. xclip is not on your system by default, you will have to install it: sudo apt-get install xclip In its simplest form, you could do it in a very short script with the help of xclip. When we use the xclip -o command, the currently selected text is used to output, or as man xclip mentions: -o, -out ...


0

I think newer Gedit versions work with Python 3 instead of 2. So you might want to change the loader in SplitView.plugin. Change line 2 from Loader=python to Loader=python3


-1

You need to place "sudo" in front of "pip".


0

@jaysheel utekar is right. The problem is that, if your code ends up in the else case of your if statement, variable tx_rate is not defined. This causes the calculation in line 47 to throw an exception. But there are a few more problems with your code: if 'ans1' == 'yes': will always result in False, because you are comparing two different strings and not ...


1

You should probably try defining tx_rate=0.15 before your if...else conditions. Because when your user inputs nothing for the first question where you ask for yes or no it directly goes to the else part where there's no tx_rate so giving you error "variable not defined"


2

Install Pip for Python3 sudo apt-get install python3-pip And then use it to install packages into Python3 sudo pip3 install paperclip


1

In python: Since the split definition is not exactly similar for both delimiters (the dot needs to be included, while the space does not), you need two steps to split: In a (long) one-liner: python3 -c "s = open('f').read().strip(); [print(s[:n]) for n in reversed(sorted([i+1 for i, c in enumerate(s) if s[i] == '·']+[i for i, c in enumerate(s) if s[i] == ...


0

As @saiarcot895 said through his comment months ago, Qt 5 is included in the default repositories. I run sudo apt-get install qt5-default . The problem is fixed


-1

Did some additional research, and installing setuptools and running easy_install on the package solved the problem for me.


4

$ echo $sentence | awk -F'[· ]' '{out=$0;print;for (i=NF;i>1;i--){out=gensub(/([· ])[^· ]*[· ]?$/, "\\1", "g", out); print out }}' Hel·lo my name is E·ric Hel·lo my name is E· Hel·lo my name is Hel·lo my name Hel·lo my Hel·lo Hel·


0

Run python interpreter and check in modules that do you have sqlite3 module installed or not.If not install it by running. sudo apt-get install python-sqlite Now run your django project Or do as given in this link "No module named 'pysqlite2'" Error


0

The cause of my problem was a corrupt file. The data in the field that I was using came from that file. I fixed the file, all the logic works as expected. Thank you for your time and effort. I learned a more about python from your answer.


1

Ubuntu 15.04 comes with both Python 2.7 and Python 3.4. At the command line you can call Python 2.7 by using python, python2 or python2.7, and Python 3.4 by using python3 or python3.4. Software Center uses Python 2.7, so if you can use Software Center you still have Python 2.7 installed .


1

In ubuntu python is already installed(default) open the terminal type python you can see python 2.7.x shell or python3 you can see python 3.4.x shell


0

Try this: iptables -F and try to connect again to the port 8000, even if you have not changed your firewall, maybe your distro comes with a pre configured firewall. The previous command makes a flush (-F) to the firewall's tables, all chains are cleaned, basically deactivate the firewall. If you are working with ufw (Uncomplicated Firewall), use the ...


-3

You can install anaconda package in ubuntu following this instruction.In that way along with python you will get other mostly used python packages as well. Or you can install the basic python following these instructions First install dependencies sudo apt-get install build-essential checkinstall sudo apt-get install libreadline-gplv2-dev libncursesw5-dev ...


0

You are removing all duplicate lines, not just 'Test'. My quick take. def delete_duplicate(inputfile,outputfile): output = open(outputfile, "w") input = open(inputfile, "r") current_test = '' for line in lines: if line == current_test: pass else: if line[:4] == 'Test': current_test = ...


2

Assuming your question is "How can I install django?", I might suggest that you do so using pip (python's package manager). There are other options, but this method has been the most pleasant in my experience. For python3, you can install pip with sudo apt-get install python3-pip Change python3-pip to python-pip in the command above if you are using ...


2

Unless you have a good reason for specifically requiring a different version, then install Django from the repos: sudo apt-get update && sudo apt-get install python-django


1

The correct syntax is notify-send [OPTIONS] <summary> [body] Eg: notify-send -u normal "Hello World" "Have a nice day" Have a look at man notify-send If you want to use an other library (in your case irssi-libnotify) and there is a bug, create an issue on GitHub. Example notify-send -u critical "IRC" "This is a critical IRC notification" ...


0

In my applications I tend to replace os.system() and subprocess.call() with subprocess.Popen (see http://stackoverflow.com/a/636570/2372604).


0

You can install django with pip3, which is an easy way. Follow below to install pip3 and django: sudo apt-get update. Update your repositories to get the latest application versions available in your repositories. sudo apt-get install python3-pip. This will download pip3. sudo pip3 install django. This will download the latest global django version for ...


0

In awk associative arrays are traversed in a non-determined order. Replace your for (i in a) by n = i for(i=1;i<=n;i++) To enclose your awk in a bash script you can use something like #!/bin/bash for file do awk -v file="$file" '....' "$file" done Make sure you run chmod a+rx on the script file. Also replace the line fn="file" c; in your ...


0

I needed to add #!/usr/bin/python To the top of the Script and remove python from crontab entry


4

For Django, the quickest way might be to stop generating them in the first place. Now, that might sound like a terrible idea... Bytecode precompilation is what makes Python as fast as it is so it's definitely something you want in production, but we can disable bytecode generation just for things run through manage.py. Open it up and add a ...


2

Did you recently install the latest version of the python-package requests? That one is incompatible with the old pip version shipped with Ubuntu! You need to reinstall the current version of pip and everything will be fine: sudo easy_install pip Or if you have those issues with Python3: sudo easy_install3 pip You should always keep your python ...


4

You can use the subprocess module : #!/usr/bin/env python2 import subprocess command_1 = 'ps -eo pid,ppid,user,rss,comm --sort=rss'.split() command_2 = 'tail -10'.split() first = subprocess.Popen(command_1, stdout=subprocess.PIPE) subprocess.call(command_2, stdin=first.stdout) command_1 is the command on the left of the pipe, split on spaces to make a ...


3

I'd use something like psutil to grab the data programmatically. That's going to take a little while to learn so the quicker, scrappier alternative is to run the commands through a subshell-style construct from Python. import commands exit_code, output = commands.getstatusoutput('ps -eo pid,ppid,user,rss,comm --sort=rss') print ...


2

Removed "Precise" from /etc/maas/bootresources.yaml and it's now working


1

I got it to work by first installing "software-properties-common" as suggested in the comments: sudo apt-get install software-properties-common sudo apt-add-repository ppa:fkrull/deadsnakes sudo apt-get update sudo apt-get install python3.2


0

You can stop it using: sudo fuser -k 8000/tcp This kills the process you have on your port 8000


1

The easiest way is to follow this Q&A with two small exceptions: Don't delete the home directory and don't link to an external HDD (steps 4 & 5) Then you'll have a fully working Ubuntu-on-a-stick… :-)


3

The files are present in /usr/lib/python2.7/dist-packages, therefore uninstall with sudo rights. sudo  pip uninstall South


0

I had this issue and had a dodgy python-apt package from another source. I removed those sources from apt manually by editing /etc/apt/sources.list and removing files from /etc/apt/sources.list.d and then doing: apt-get update apt-get remove python-apt apt-get install update-manager-core This last one will reinstall python-apt, which should come from ...


0

It is a problem of pycuda. setup.py of pycuda checks nvcc command and guesses a root directory of CUDA. https://github.com/inducer/pycuda/blob/master/setup.py#L30 ..., and then it sets include directory of CUDA. https://github.com/inducer/pycuda/blob/master/setup.py#L93 All you need is set path correctly before pip. PATH=/usr/local/cuda-7.0/bin:$PATH ...


0

The Complete Solution of the problem is I installed python 3.4.3 from python.org as a tar file after extraction I symlink to python, where it was already available in ubuntu 14.04 as python3. Actually some packages on ubuntu 14.04 were dependent on python 2.7 so the symlink to python 3.4.3 was causing all problems. How to solve it .. `Just re symlink ...


0

It looks like you are missing a dependency for IPython Notebook. If you don't already have pip installed, I would recommend installing it for the ease of installing python packages: sudo apt-get install python-pip python-dev build-essential Once pip has been installed, you can install the IPython Notebook and all its dependencies by entering at the ...


0

that is working for me without problem: sudo apt-get build-dep python-pygame than: pip install hg+http://bitbucket.org/pygame/pygame


0

It does not look like pycrypto is a dependency of unity-control-center so I do not think that this is what caused the package to be upgraded. Instead, I think that you had installed an older version of this package and when apt saw that there was a newer version available it installed if for you. This is the nature of the apt package manager. If you wish ...


0

Use double quotes to wrap the command substitution. Also either use single quotes or use double quotes in the echo command, there's no need to use both: echo 'iorem ipsum est' > textfile /usr/share/ofono/scripts/send-sms /ril_0 07123456789 "$(cat textfile)" 0


0

You should place the plugin in $HOME/.local/share/gedit/plugins and after (re)starting Gedit it should be available in Edit=>Preferences=>Plugins


0

You need to add an alias to postfix. # send to emailname@example.com emailname: "|/path/to/script.py" Then a simple two line script can get your the email object. import email msg = email.message_from_file(sys.stdin)


3

Alternative to using sys.argv is using argparse. Very helpful if you need more command line parameter parsing. #!/usr/bin/env python2 import argparse def main(files): for f in files: print "Would do something with", f if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('file', nargs='+', help='path to the ...


1

Use the sys.argv as list, providing all individual files as arguments and have your shell (e.g. Bash) expand it for you. script.py looks like: #!/usr/bin/env python2 import sys def main(files): for f in files: print "Would do something with", f if __name__ == "__main__": files = sys.argv[1:]: # slices off the first argument (executable ...


3

Extending muru's answer a bit: Why not do it all inside your python script? Transform the script's actions on the files into a function, then run the script with the directory as an argument: #!/usr/bin/env python3 import os #--- your original script, transformed into a function def some_function(file): print(file) #--- # The directory with your ...


5

Use sys.argv[1] so that the filename is taken from the arguments: import sys with open(sys.argv[1],'r') as in_file Then, you can use various methods to pass the filename as an argument. For example, with find: find test/ -type f -name '*.csv' -exec /path/to/script.py {} \;


2

You'll have to retrieve the filename within the python script for this to work: #!/bin/bash for f in *.csv; do python script.py "$f" done In a one-liner: for f in *.csv; do python script.py "$f"; done



Top 50 recent answers are included