Tag Info

Hot answers tagged

12

First, install the xdotool command: sudo apt-get install xdotool Then, create an alias to be able to run min as a command: echo 'alias min="xdotool getactivewindow windowminimize"' >> ~/.bashrc` Reload the .bashrc file: . ~/.bashrc


10

How to know if a python module is installed or not in the system: You can do a very easy test in terminal, $ python -c "import math" $ echo $? 0 # math module exists in system $ python -c "import numpy" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named numpy $ ...


10

In case we do not want to unwantedly import a module in question (which would happen in a try statement) we can make use of sys.modules to test modules that are installed and were imported before. In the python shell issue: >>> import sys Then test for installed modules: >>> 'numpy' in sys.modules True >>> 'scipy' in ...


7

The following python oneliner will minimize the current gnome-terminal window: python3 -c "from gi.repository import Gdk; \ [ Gdk.Screen.get_default().get_active_window().iconify() for i in range(2)]" Note that we need to call iconify() two times to minimize the window.


7

Another way is the pkgutil module. Works with both Python 2 & 3: python -c 'import pkgutil; print(1 if pkgutil.find_loader("module") else 0)' You need to replace module with the name of your module, example: $ python -c 'import pkgutil; print(1 if pkgutil.find_loader("math") else 0)' 1


5

I know the OP originally asked for a solution after starting Python, but outside of python I use pip. On ubuntu: sudo apt-get install python-pip, if it's not already installed. Then to see what third party modules are available, just run: pip freeze Or even pip list And both will show you all modules installed and their versions. If the module you're ...


5

You could put the code inside try, except block. $ python3 -c "\ try: import cow print('\nModule is installed') except ImportError: print('\nThere is no such module installed')" There is no such module installed $ python3 -c "\ try: import regex print('\nModule is installed') except ImportError: print('\nThere is no such ...


5

You're missing the QtGui import. Most of NameError: name 'foo' is not defined are related to missing imports when foo is expected to be a library. In your case add this: from PyQt4 import QtGui


4

To provide another answer, for completion's sake: You can (ab)use the -m option. From Python's manpage: -m module-name Searches sys.path for the named module and runs the correspond‐ ing .py file as a script. Which will give us: $ python2 -m numpy /sbin/python2: No module named numpy.__main__; 'numpy' is a package and cannot be ...


3

How it works (python2): python /path/to/script.py works if file is either executable or not shebang (#!/usr/bin/env python) in the head of the script is good practice, but not needed /path/to/script.py works if script is executable shebang is needed (#!/usr/bin/env python) script.py works if script is in $PATH script needs to be executable filename ...


3

Your IPython and IDLE editions are based on different major versions of Python (2 and 3 respectively). For your projects you need to use either one or the other for consistency. The relevant package names for the two Python versions are: Python 2: idle ipython python-numpy python-scipy Python 3: idle3 ipython3 python3-numpy python3-scipy You can install ...


2

Do you need Python? You can count words using the command line tool wc: wc -w * wc (short for word count) is a handy tool to count words, characters or lines in text files. Open a terminal, navigate to the folder containing the files you want to count words and run the command above. The first parameter -w means to count words (as opposed to lines or ...


2

As mentioned, your code is not really clear to me. One of the mistakes you make is that you put the linenum_words = 0 inside the loop, which means that on every subfolder, you would start counting from 0. If you want to use python, what would work anyway is to use os.walk, which would count the words in all files in a directory and its subdirectories, no ...


2

You can just use keybindings of Ctrl+Space to open the window menu, then press N (in an English locale) to minimize the window.


2

There is a python library used to interact with Git repositories It can be used in Fetching Remote Git Repo with Python, e.g.. There's also the old fashioned way cd /path/to/git/repo python3 my_favorite.py But I think you will find Git to be Python version independent, and that possibly you want to associate Python code, files and extensions with Python ...


1

There would be multiple ways of doing this. First, change the sym-links around so that the python in /usr/bin/ would actually be pointing to the same location as the /usr/bin/python3 sym-link. However, this is a bad idea (as I explain below). The second option would be to create a user-specific command alias - this is definitel the better option of the ...


1

Ubuntu 14.10 comes with Python 2.7.8 and Python 3.4.2 so you should keep them. Python 3.3.2+ isn't in the official software repositories and no program from there needs it. But you may have programs from other sources which depend on it.


1

python3.3-minimal contains the interpreter and some essential modules. It can be used in the boot process for some basic tasks. See /usr/share/doc/python3.3-minimal/README.Debian for a list of the modules contained in this package. Yet as Florian Diesch explains Python 3.3.2+ is unofficial and not a necessity unless you have programs dependent on that ...


1

I would not recommend to have two 2.7.x versions installed. If you need for some project a specific additional version, use virtual environments instead. If you need to get rid of one python system wide version, stick to this recommendations. To change between different installations of python, use sudo update-alternatives --config python to configure ...


1

To install through > bash Anaconda.. you need to have bzip2 installed sudo apt-get install bzip2 then follow Hayd's suggested procedure Also make sure to install it on your home dir (without root) and to source .bashrc so you do not have to open a new session as requested source ~/.bashrc then proceed with conda update pandas Hope that helps!


1

First, you should enter as root: sudo -i and then run your command pip install ipython


1

You have not specified the Python interpreter to use to create your virtual environment in ~/Public/Programming/project1/ directory. From man virtualenv: -p PYTHON_EXE,--python=PYTHON_EXE The Python interpreter to use to create the new environment. The -p option expects the next argument to be the python interpreter on which the new environment would be ...


1

Literally speaking, what is happening here is the code expects two values out the back of line.strip().split(' ||| ',1) (so it can assign those to s and r) but it's only getting one. Thus it explodes. That's happening because you're not using the script correctly. If you look at the --help (or further up the code, line ~90), you'll see that it expects a ...


1

You should also use the startapp command. Please follow this tutorial: https://docs.djangoproject.com/en/1.7/intro/tutorial01/


1

Step 1: Where are the shared objects seeming to be? schadenfreude@oubliette:~$ locate libpython3.4 | grep /usr/lib | grep so /usr/lib/debug/usr/lib/libpython3.4m.so.1.0-gdb.py /usr/lib/debug/usr/lib/x86_64-linux-gnu/libpython3.4m.so.1.0 /usr/lib/python3.4/config-3.4dm-x86_64-linux-gnu/libpython3.4.so ...



Only top voted, non community-wiki answers of a minimum length are eligible