How to install matplotlib with Python3.2

Matplotlib supports python 3.x as of version 1.2, released in January, 2013. To install it, have a look at the installation instructions. In general, call pip install matplotlib or use your preferred mechanism (conda, homebrew, windows installer, system package manager, etc). In some cases you may need to install additional non-python dependencies (libpng and freetype) … Read more

Sending mail error with python smtplib

The following works for microsoft, google, yahoo accounts on Python 2.7 and Python 3.2: #!/usr/bin/env python # -*- coding: utf-8 -*- “””Send email via smtp_host.””” import smtplib from email.mime.text import MIMEText from email.header import Header ####smtp_host=”smtp.live.com” # microsoft ####smtp_host=”smtp.gmail.com” # google smtp_host=”smtp.mail.yahoo.com” # yahoo login, password = … recipients_emails = [login] msg = MIMEText(‘body…’, ‘plain’, … Read more

How to read an array of integers from single line of input in python3

Use map: arr = list(map(int, input().split())) Just adding, in Python 2.x you don’t need the to call list(), since map() already returns a list, but in Python 3.x “many processes that iterate over iterables return iterators themselves”. This input must be added with () i.e. parenthesis pairs to encounter the error. This works for both … Read more

PyEval_InitThreads in Python 3: How/when to call it? (the saga continues ad nauseam)

Your understanding is correct: invoking PyEval_InitThreads does, among other things, acquire the GIL. In a correctly written Python/C application, this is not an issue because the GIL will be unlocked in time, either automatically or manually. If the main thread goes on to run Python code, there is nothing special to do, because Python interpreter … Read more

How to know/change current directory in Python shell?

You can use the os module. >>> import os >>> os.getcwd() ‘/home/user’ >>> os.chdir(“/tmp/”) >>> os.getcwd() ‘/tmp’ But if it’s about finding other modules: You can set an environment variable called PYTHONPATH, under Linux would be like export PYTHONPATH=/path/to/my/library:$PYTHONPATH Then, the interpreter searches also at this place for imported modules. I guess the name would … Read more