Pandas not working in python3 but works in python - python

I tried to run pandas in python3. But I get the following error.
user#client3:~/smith/Python$ python3
Python 3.7.0 (default, Oct 3 2018, 21:22:25)
[GCC 5.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
So I tried to run from python,
user#client3:~/smith/Python$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> exit()
It works fine here. So I tried to install pandas for python3 as follows,
user#client3:~/smith/Python$ sudo apt-get install python3-pandas
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pandas is already the newest version (0.17.1-3ubuntu2).
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-139 linux-headers-4.4.0-139-generic linux-image-4.4.0-139-generic linux-image-extra-4.4.0-139-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.
It already installed for python3. What happened here? Why it doesn't run for python3?

This should work, check it out.
pip3 install pandas

Related

import opencv with anaconda using python package

I'm currently working on a project with anaconda. I was able to install opencv-python with the regular pip3 install (not anacondas version). When I import cv2, its successful.
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
If I copy that package into my anaconda path, and run python with anaconda, import cv2 I get the following error:
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Is there a way to get around this without using the Anacondas pip install? I don't have internet on the machine I'm working on. I've done this method with other packages and it has worked fine, not with opencv.

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'
>>>

No module named 'nltk'

I successfully installed nltk and works fine. I have to run a file where nltk was imported and tensorflow too ,hence, i have to activate tensorflow.
When I activate tensorflow the .py file i want to run gives an error. I have read some solution but they didn't help.
HP-250-G5-Notebook-PC:~$ python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
this works fine but this does not
(tensorflow)HP-250-G5-Notebook-PC:~/AIG2018/Chatbot$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
What is that I am doing worng?
ImportError: No module named 'nltk'
You're using two different versions of python, and you probably installed nltk in your root environment, but not your virtual environment. When you "activate" the environment called tensorflow, you are using a different virtual environment, in which you haven't installed nltk. Try activating tensorflow, then using pip install nltk, then starting python. Because you seem to be using anaconda, this would probably look like this:
# Do these first 2 steps in your terminal:
source activate tensorflow
# you're now in the virtual environment called tensorflow
pip install nltk
# you now have nltk in that virtual environment
# Now, you can start python
python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
And you shouldn't have that error
If you look closely at your messages you will see that the successful import of nltk is on Python 3.6.3 and the failed import is on Python 3.5.2.
This indicates that you have two Python installations of different versions, and nltk is installed in one but not in the other.

sympy 0.7.1 plot does not work

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.

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