Re: [Tutor] Plotting with python

2015-11-03 Thread Oscar Benjamin
On 31 October 2015 at 00:00, Terry Carroll  wrote:
> If you were going to get started doing some simple plotting with Python 2.7
> (in my case, I'm simply plotting temperature against time-of-day) what would
> you use?
>
>  - matplotlib [1]
>  - gnuplot [2]
>  - something else entirely?

I'd use matplotlib.

> Assume no substantial familiarity with the underlying plotting software, let
> alone the Python bindings.
>
> The only thing I can think of that might be special is to specify the
> upper/lower bounds of the plot; for example, in my case, I know the
> temperatures vary between somewhere around 70-78 degrees F., so I'd want the
> Y-axis to go, say 60-90, not arbitrarily start at zero; but I suspect this
> is a pretty standard thing in almost any plotting package.

This is straightforward in most plotting packages. Here's a simple
example of doing it in matplotlib:

#!/usr/bin/env python3

import matplotlib.pyplot as plt

times = [0, 1, 2, 3, 4, 5]  # hours
temperatures = [68, 70, 75, 73, 72, 71] # Fahrenheit

fig = plt.figure(figsize=(5, 4))
ax = fig.add_axes([0.15, 0.15, 0.70, 0.70])
ax.plot(times, temperatures)
ax.set_xlabel('Time (hours)')
ax.set_ylabel(r'Temp ($^{\circ}\mathrm{F}$)')
ax.set_title('Temperature vs time')

plt.show()

--
Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Missing Standard Libraries on Python 3.5 for Mac

2015-11-03 Thread Andrew Machen
Hi,

I am new to Python, and I am trying to use a Python Standard Library, namely 
‘unicodedata’, however it appears to be missing (others are also missing) from 
the built-in libraries that come with Python 3.5 for Mac. 

I have searched the following directory, but have not found the library:

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5

I have tried reinstalling Python 3.5 and also tried Python 3.4.3, and neither 
install the ‘unicodedata’ library. Is there anyway to install it manually?

The library is present in the Python 2.7 version provided by Apple, however I 
was hoping to learn and use Python 3. The library is present in the Linux 
version of Python 3.5 that I have tried.

Your help is greatly appreciated.

-Andrew
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] ImportError: No module named connect

2015-11-03 Thread Tommy Peterson
I have been trying to install the MySQL Connect module for a day and a half. 

First I got an error saying that "No module named mysql" was installed. After a 
lot of trial and error I got passed that. I realized that because I have python 
installed in /usr/local that I needed to build and then install the library 
into site-packages where Python was looking. But now it appears that the 
submodule "connect" cannot be located. 

Some people have suggested online that I needed to make sure the module was 
added to the system path by doing this: 
import sys
sys.path.insert(1,'//usr/local/lib/python2.4/site-packages/mysql')
import mysql
Some have suggested that I needed to edit the __init__.py file in /mysql/ with 
this:
from pkgutil import extend_path
path = extend_path(path, name)

But after I built and then installed pointing to my site-packages directory the 
__init__.py file in /usr/local/lib/python2.4/site-packages/mysql/ has that code 
already. The __init__.py in mysql/connector/ has a lot of stuff. It uses dot 
notation as well which is beyond my rudimentary Python knowledge: for example:
from . import version
from .connection import MySQLConnection

It appears this is related to the install and that I am using 
/usr/local/lib/python2.4/site-packages. But I am running out of ideas to try. I 
am not Python expert as you can tell. 

Any suggestions? 

Again the error in my script where I try to import mysql.connection to connect 
to mysql is:
import mysql.connect
ImportError: No module named connect

The installation instructions are :
http://dev.mysql.com/doc/connector-python/en/connector-python-introduction.html

Also I have tried installing it via yum. No go there either. 
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ImportError: No module named connect

2015-11-03 Thread Tommy Peterson
As I typed this out I double checked something. I resolved my own problem. 
Should have stepped back before posting. 

It is 

import mysql.connector
not
import mysql.connection

From: stpete...@hotmail.com
To: tutor@python.org
Subject: ImportError: No module named connect
Date: Tue, 3 Nov 2015 12:59:26 -0500




I have been trying to install the MySQL Connect module for a day and a half. 

First I got an error saying that "No module named mysql" was installed. After a 
lot of trial and error I got passed that. I realized that because I have python 
installed in /usr/local that I needed to build and then install the library 
into site-packages where Python was looking. But now it appears that the 
submodule "connect" cannot be located. 

Some people have suggested online that I needed to make sure the module was 
added to the system path by doing this: 
import sys
sys.path.insert(1,'//usr/local/lib/python2.4/site-packages/mysql')
import mysql
Some have suggested that I needed to edit the __init__.py file in /mysql/ with 
this:
from pkgutil import extend_path
path = extend_path(path, name)

But after I built and then installed pointing to my site-packages directory the 
__init__.py file in /usr/local/lib/python2.4/site-packages/mysql/ has that code 
already. The __init__.py in mysql/connector/ has a lot of stuff. It uses dot 
notation as well which is beyond my rudimentary Python knowledge: for example:
from . import version
from .connection import MySQLConnection

It appears this is related to the install and that I am using 
/usr/local/lib/python2.4/site-packages. But I am running out of ideas to try. I 
am not Python expert as you can tell. 

Any suggestions? 

Again the error in my script where I try to import mysql.connection to connect 
to mysql is:
import mysql.connect
ImportError: No module named connect

The installation instructions are :
http://dev.mysql.com/doc/connector-python/en/connector-python-introduction.html

Also I have tried installing it via yum. No go there either. 

  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Missing Standard Libraries on Python 3.5 for Mac

2015-11-03 Thread Zachary Ware
Hi Andrew,

On Tue, Nov 3, 2015 at 11:20 AM, Andrew Machen
 wrote:
> Hi,
>
> I am new to Python, and I am trying to use a Python Standard Library, namely 
> ‘unicodedata’, however it appears to be missing (others are also missing) 
> from the built-in libraries that come with Python 3.5 for Mac.
>
> I have searched the following directory, but have not found the library:
>
> /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5

Have you tried importing it?  If importing it works, you can then find
where it lives by checking the __file__ attribute:

import unicodedata
print(unicodedata.__file__)

> I have tried reinstalling Python 3.5 and also tried Python 3.4.3, and neither 
> install the ‘unicodedata’ library. Is there anyway to install it manually?

It should be included with your installation, assuming you're using
the package from python.org.  If you are unable to import it, please
raise an issue on the bug tracker at bugs.python.org.

For the record, here's where unicodedata lives on my Mac:
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload/unicodedata.cpython-35m-darwin.so

Note that unicodedata is implemented in C, so it does not have a .py extension.

-- 
Zach
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ImportError: No module named connect

2015-11-03 Thread Steven D'Aprano
On Tue, Nov 03, 2015 at 12:59:26PM -0500, Tommy Peterson wrote:
> I have been trying to install the MySQL Connect module for a day and a half. 

I see that you believe that you have solved your problem ("from mysql 
import connector" rather than "connect" or "connection") but for the 
record you have other problems. 

I recognise that, right now, you probably have a working system and the 
last thing you want to do is mess with it, but trust me, whoever has to 
maintain your system in the future is going to be *utterly confused* by 
your setup. If you choose to ignore this ("hey, my system works, I'm not 
going to mess with it") at least copy this post into your site wiki (if 
you have one) or put it in a README file somewhere where the next guy 
(or even you, in the future) can see it. Because your Python setup is 
*seriously* weird.

You talk about using the site-packages in python2.4. Why are you using 
Python 2.4? That's ancient. I see that you are using a Redhat based 
system, as you refer to yum, but it doesn't make sense that you have 
Python 2.4 in /usr/local/lib.

In old Centos/Fedora/Redhat systems, where Python 2.4 is still used, we 
have the path set here:

/usr/lib/python2.4/

*not* /usr/local/lib. Perhaps you are using a more recent RH-based 
system, which defaults to Python 2.6 or 2.7. So why have you installed 
2.4? It's so old that the mysql package won't work. I know it won't work 
because mysql __init__.py includes the dot notation

from . import version

which is a SyntaxError in Python 2.4.

So it appears that:

- you have installed Python 2.4 in a non-standard place;
- installed a package for 2.6 or higher in the 2.4 site-packages;
- and are running Python 2.6 or higher using the 2.4 site-packages.

Anyone who has to maintain or administer your system is going to be 
horribly confused.

Despite the references to 2.4 site-packages, I expect you are using 
Python 2.6 or higher. You ought to be able to install the Python mysql 
library using yum. On my Centos system, I can do this:

[root@ando ~]# yum search mysql-python
[...]
MySQL-python.i386 : An interface to MySQL
python26-mysqldb.i386 : An interface to MySQL


so all I need to do is:

sudo yum install mysql-python

to install into the system Python 2.4, or:

sudo yum install python26-mysqldb

to install into the yum-provided Python 2.6 installation. I don't know 
which precise RH-based system you are using, but I would be *astonished* 
if it didn't support the mysql package appropriate for your version of 
Python. Installing things by hand, as you appear to have done, is not 
needed.


Some further comments about the quality of advice you appear to have 
been given:

> Some people have suggested online that I needed to make sure the 
> module was added to the system path by doing this:
> import sys
> sys.path.insert(1,'//usr/local/lib/python2.4/site-packages/mysql')

I don't know who "some people" are, but that's clearly wrong. 
site-packages will be automatically installed in the path (unless 
something has gone horribly, horribly wrong!). And, you don't need to 
add the package itself (mysql in this case) to the path. Well, you can, 
but it goes against the concept of a self-contained package. It's 
certainly not the right way to fix the problem.



> import mysql
> Some have suggested that I needed to edit the __init__.py file in /mysql/ 
> with this:
> from pkgutil import extend_path
> path = extend_path(path, name)

Absolutely not. Again, there are thousands of users of mysql. If 
submodules couldn't be imported, surely they would have noticed, and the 
mysql package fixed.

Having to hack a buggy package in that way might be a reasonable 
suggestion for some sort of minor, half-debugged and slightly dodgy 
library with one maintainer and three users, but certainly not for 
something as widely-used as mysql.

 
> But after I built and then installed pointing to my site-packages 
> directory the __init__.py file in 
> /usr/local/lib/python2.4/site-packages/mysql/ has that code already. 
> The __init__.py in mysql/connector/ has a lot of stuff. It uses dot 
> notation as well which is beyond my rudimentary Python knowledge: for 
> example:
>
> from . import version
> from .connection import MySQLConnection

As I mentioned above, this dot notation is not supported by 
Python 2.4. But you've installed the package into the 2.4 site-packages. 
If you ever run Python 2.4, this could cause problems for you.


Good luck!


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor