Reputation: 1000
I'm on Ubuntu using Jupyter Notebook. I'm a newbie (to coding and ubuntu) trying to learn how to access databases with Python.
Can some explain what the problem I'm having is?
This is the process I went through:
I thought I had installed PyMySQL.
I ran this:
import pymysql
and got this error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-3dee6b071588> in <module>()
----> 1 import pymysql.cursor
ImportError: No module named 'pymysql'
I assumed that I hadn't installed it and went to terminal and ran:
sudo pip install PyMySQL
and got this result
The directory '/home/username/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Requirement already satisfied: PyMySQL in /usr/local/lib/python2.7/dist-packages
I then ran:
sudo -h pip install PyMySQL
install: missing destination file operand after 'PyMySQL'
Try 'install --help' for more information.
Upvotes: 1
Views: 6995
Reputation: 3706
Does Jupyter Notebook have some form of terminal emulator that you're using?
If it does try using ubuntu's terminal. Ctrl+Alt+T
is a shortcut to do so.
Then try either one of these commands to download PyMySQL
for your version of python, after installing pip.
sudo apt-get install python-pip
sudo pip install PyMySQL
sudo pip2 install PyMySQL
sudo pip3 install PyMySQL
Finally import the PyMySQL package.
import pymysql
Upvotes: 1
Reputation: 1000
In terminal I entered
sudo pip3 install PyMySQL
Got the following message and response.
The directory '/home/username/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting PyMySQL
Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB)
100% |████████████████████████████████| 81kB 1.1MB/s
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.7.11
In Jupyter I ran
import pymysql
Didn't get any error messages. Seems to have worked.
Upvotes: 0