sympy 0.7.1 plot does not work - python

how can i fix this, or find the logs to investigate it?
$ python
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import symbols
>>> from sympy.plotting import plot
OpenGL Warning: Failed to connect to host. Make sure 3D acceleration is enabled for this VM.
>>> x = symbols('x')
>>> p1 = plot(x*x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> import sympy
>>> sympy.__version__
'0.7.1.rc1'
it looks like the plotting module has not been fully installed?

this seems to be a very old version of sympy. the api has changed. in sympy 0.7.1.rc1, plot is a module, not a function.
i solved the issue by removing the existing versions of mpmath and sympy (which had been installed with apt) and installing the latest versions like so:
$ sudo apt-get remove --purge python-mpmath python-sympy
$ sudo python -m easy_install mpmath
$ python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mpmath
>>> mpmath.__version__
'0.19'
$ sudo python -m easy_install sympy
$ python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy
>>> sympy.__version__
'0.7.6'
now plot() shows the graph.
in future, use python -m easy_install to install the latest version, and not apt-get which has old versions it seems.

Related

RPi.GPIO Not Found in Python 3

I am trying to get the GPIO module working on a Raspberry Pi 3B+. I have installed the libraries as below. It works fine in Python2 but not Python 3 (version 3.9). Any ideas would be appreciated.
pi#raspberrypi:/usr/bin $ sudo apt-get install python-rpi.gpio python3-rpi.gpio
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-rpi.gpio is already the newest version (0.6.5~stretch-1).
python3-rpi.gpio is already the newest version (0.6.5~stretch-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
pi#raspberrypi:/usr/bin $ python2
Python 2.7.13 (default, Aug 22 2020, 10:03:02)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
>>>
pi#raspberrypi:/usr/bin $ python3
Python 3.9.0 (default, Jan 27 2021, 16:17:29)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'RPi'
>>>

I installed flask on my laptop. But it seems to be running only for python3. How to make it work for python2?

My system has python3 as the default for python command.
when I try to import flask on python command line I get this:
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named flask
>>>
but in python3 i get this:
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>
How do i correct this?
It looks you are using two different packaging systems: pip and conda. For Python2, try pip2 install flask.

Python3.5 Refuse to Work with MySQL Connector

I've read a few questions on here that people are having the same situation as me but no matter what method I tried, it just wouldn't work!
According to MySQL documentation, MySQL-connector-python-2.x.x.x should work with Python 3+. I've downloaded the RPM package and installed it inside my virtualenv. However, upon importing the library, I get the error, "No module named MySQL".
Checking to see if I've installed the package:
(virtual)[centos ~]$ rpm -ql mysql-connector-python-2.1.3-1.el6.x86_64.rpm
package mysql-connector-python-2.1.3-1.el6.x86_64.rpm is not installed
Attempting to install the package:
(virtual)[centos ~]$ sudo rpm -i ~/Documents/python/mysql-connector-python-2.1.3-1.el6.x86_64.rpm
[sudo] password for <username>:
warning: /home/<username>/Documents/python/mysql-connector-python-2.1.3-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
package mysql-connector-python-2.1.3-1.el6.x86_64 is already installed
This works on Python2.6:
[centos ~]$ python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> import mysql.connector
>>>
Doesn't on Python3.5:
[centos ~]$ python3.5
Python 3.5.1 (default, Jan 13 2016, 17:43:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'mysql'
>>>
Verified the package through MySQL documentation:
(virtual)[centos]$ python
Python 3.5.1 (default, Jan 13 2016, 17:43:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from distutils.sysconfig import get_python_lib
>>> print (get_python_lib ())
/home/<username>/Documents/redhat-server/python_project/virtual/lib/python3.5/site-packages
>>>
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'mysql'
>>>
Making sure that python3.5 is in the same directory as MySQL.connector
(virtual)[centos]$ which python3.5
~/Documents/redhat-server/python_project/virtual/bin/python3.5
Update:
(virtual)[centos]$ pip install mysql-connector-python
Collecting mysql-connector-python
Could not find a version that satisfies the requirement mysql-connector-python (from versions: )
No matching distribution found for mysql-connector-python
(virtual)[centos]$
What am I doing wrong?
I've figured it out. Anzel was right about the fact that it's installed globally in the default python2.6 directory. Here's how I fixed it:
Launch the default python interpreter, in my case "python" -> python2.6, and run the commands below to see where "MySQL.connector" was installed.
>>> from distutils.sysconfig import get_python_lib
>>> print get_python_lib ()
/usr/lib/python2.6/site-packages
>>>
Navigate to the above directory, "/usr/lib/python2.6/site-packages/" reveal a directory called MySQL, and a file called, MySQL_connector_python-2.1.3-py2.6.egg-info.
Launching python3.5 interpreter leads me to a different path, which I checked and sure enough, the two MySQL and MySQL_connector_python-2.1.3-py2.6.egg-info file/directory wasn't there.
>>> from distutils.sysconfig import get_python_lib
>>> print (get_python_lib ())
/home/<username>/Documents/redhat-server/python_project/virtual/lib/python3.5/site-packages
>>>
Next, I copied those 2 files to Python3.5 site-packages directory, tested the import, database connections, and it worked!
Python 3.5.1 (default, Jan 13 2016, 17:43:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "copyright", "credits" or "license()" for more information.
>>>
>>> import mysql.connector
>>>
>>> cnx = mysql.connector.connect (user = 'username', password = 'password', host = 'localhost',
database = 'testdb')
>>> cnx
<mysql.connector.connection.MySQLConnection object at 0x7ffa4c1009b0>

why matplotlib is not operating?

I want to use matplotlib. I have installed it as:
sudo apt-get install python-matplotlib
and in terminal I have:
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'1.3.1'
>>> matplotlib.__file__
'/usr/lib/pymodules/python2.7/matplotlib/__init__.pyc'
>>> mpl.get_configdir()
'/home/azh2/.config/matplotlib'
>>>> mpl.get_cachedir()
'/home/azh2/.cache/matplotlib'
now I want to use it. so in pycharm terminal I have:
$ from PIL import Image
from: can't read /var/mail/PIL
What is the problem please? can you help me solve it?
Thank you very much for your help.
You are in shell not in python executing environment.

Why pymongo doesn't work with python3 and it only works with python2

user#ubuntu:~/Documents/MongoDB$ python2
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pymongo import Connection
>>>
user#ubuntu:~/Documents/MongoDB$ python3
Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pymongo import Connection
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pymongo
Question> I don't know why pymongo doesn't work with my python 3. Any idea?
// Updated solution for this OP based on the helps below //
First, still don't understand why this post got down-vote!
Step1> http://pypi.python.org/pypi/pymongo3#downloads
Step2> Download pymongo3-1.9b1.tar.gz
Step3> unzip it by using tar xzf pymongo3-1.9b1.tar.gz
Step4> cd pymongo3-1.9b1
Step5> sudo python3 setup.py install
If you followed all above instructions, the pymongo should be ready
for your P3:)
Probably because you didn't install it for Python 3. You have to install a module for each version of Python that you have in order to access it from that version.This is all assuming that the module is compatible with each version of Python that you have.

Categories

Resources