Trying to test my python library, it's installed but not found - python

When I try to install my library locally and test it, it shows up as installed:
PS C:\Projects\pypi\potatoutils> pip install -e .
Obtaining file:///C:/Projects/pypi/potatoutils
Installing collected packages: potatoutils
Attempting uninstall: potatoutils
Found existing installation: potatoutils 0.0.1
Uninstalling potatoutils-0.0.1:
Successfully uninstalled potatoutils-0.0.1
Running setup.py develop for potatoutils
Successfully installed potatoutils
But when I try to test it
PS C:\Projects\pypi\potatoutils> python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import potatoutils
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'potatoutils'
What am I doing wrong?
EDIT: pip and python have the same version (3.7) and their paths match.
And the library shows up when I use pip list.

Often this is the issue if you pip install a package with pip for python2.x
but then when you attempt to import your library for python3.x
Make sure you're running installing pip packages for the correct python version.

use pip3 using pip sometimes point to python 2.x versions, that's why maybe it can help!

Okay, so I managed to get the library up and running by starting over and following these instructions:
https://medium.com/analytics-vidhya/how-to-create-a-python-library-7d5aea80cc3f
I still don't know what went wrong the first time (maybe outdated instructions?) but it no longer matters to me.

Related

ModuleNotFoundError after successful package installation

I am trying to install and use new Python packages e.g. mysql:
pip install mysql
Collecting mysqlNote: you may need to restart the kernel to use updated packages.
Using cached mysql-0.0.3-py3-none-any.whl (1.2 kB)
Collecting mysqlclient
Using cached mysqlclient-2.1.0-cp38-cp38-win_amd64.whl (180 kB)
Installing collected packages: mysqlclient, mysql
Successfully installed mysql-0.0.3 mysqlclient-2.1.0
However, if I run the code I receive the following error:
runfile('untitled1.py', wdir='')
Traceback (most recent call last):
File "untitled1.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
Also restarting the Kernel does not solve the problem:
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.29.0 -- An enhanced Interactive Python.
Restarting kernel...
I am using Spyder 5.0.0 on a fresh Anaconda 2.0.3 installation.
First, I'm not familiar with Anaconda, although from a quick search I don't think that should change anything about my answer.
From the PyPI description for mysql:
This package is a ‘virtual package’, which requires MySQL-python
(Python 2) or mysqlclient (Python 3) to install. In effect, this means
‘pip install mysql’ will actually install MySQL-python.
Since you're on Python 3, what it installs is mysqlclient. This is confirmed by the pip output Installing collected packages: mysqlclient, mysql. From the docs for that package, you can see that you have to import MySQLdb rather than mysql.

Python Modules installing properly but dont exist in editors

I want to start with I am new to the python language and am learning on my own. My issue is that I am installing the modules that I'm trying to use. The installs are successful but do not exist when I try to import them. I am using Visual Studio Code, Python 3.6, and Anaconda on Windows 10.
I am trying to use pyttsx3, SpeechRecognition and pocketsphinx.
$pip list
This gives me a very large list but does not contain either of my installed modules.
$python -m pip list
Gives me smaller output with them.
Package Version
----------------- ---------
beautifulsoup4 4.6.0
bs4 0.0.1
certifi 2018.4.16
chardet 3.0.4
click 6.7
gTTS 2.0.0
gTTS-token 1.1.1
idna 2.6
pip 10.0.1
pocketsphinx 0.1.3 #Here
pypiwin32 223
pyttsx 1.1
pyttsx3 2.7 #Here
pywin32 223
requests 2.18.4
setuptools 39.1.0
six 1.11.0
SpeechRecognition 3.8.1 #Here
urllib3 1.22
wheel 0.31.0
I know their installed but when I try to use any of the imports.
$python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyttsx3'
I am fine with this being something small on my part due to my lack of knowledge with this language, but I have done a full days worth of research trying to solve this myself.
Edit:
$pip --version
pip 9.0.1 from C:\Users\Keiro\Anaconda3\lib\site-packages (python 3.6)
You have two versions of pip perhaps two different installations of python as well. One with Anaconda and other one by main site.
Stick to one version and if you install in that use that environment in Visual Studio(Or VS Code)
You have installed those in anaconda which the standard installtion of Python wont recognize..
Open Python prompt from Anaconda Navigator >> Choose the environment (Select base for default) >> Open with Terminal [Or Open with Python]
>>python
>>import pyttsx3
In Visual Studio code set the same environment
Ctrl+Shift+P >> Select Python interpreter
Choose the anaconda location.
Volla. Now it should work
I had the same problem and found the answer in an old forum.
Write "pip3" instead of "pip".
So the code is:
pip3 install pyttsx3
(Source: bash: pip: command not found)

I can't find python package fftw3

I'm trying to use fftw3 on python to compute ffts really fast (using all my cores!)
The problem is... I can't find the fftw3 package for python...
I know it exists because the function I need uses it if and only if it's installed.
This is the module that I use: https://github.com/keflavich/image_tools/blob/master/fft_psd_tools/convolve_nd.py
And as expected this is what I get if I try to import it:
>>> import fftw3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fftw3
>>>
And I've tried this:
sudo pip install fftw3
sudo apt-get install python-fftw3
sudo easy_install fftw3
And I have also tried googling for its location, or installation instructions, with nothing to be found!
I am also aware that fftw is a C library and that pyfftw exists as python wrappers for that package, but the function I use utilizes fftw3.
I am hoping someone could point me to where this module is located!
P.S. I am running Ubuntu 14.04 and I'm using python 2.7. I also tried importing it in python 3 but it's not there either.
Looks like the problem was with the package you were trying to pip. I had no errors with sudo pip install pyfftw3 then import fftw3
will#will-mint2 ~ $ sudo pip install pyfftw3
[sudo] password for will:
Downloading/unpacking pyfftw3
Downloading PyFFTW3-0.2.1.tar.gz
...
Successfully installed pyfftw3
Cleaning up...
will#will-mint2 ~ $ python
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fftw3
>>> exit()
For windows
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyfftw
install it by:
pip install [filename].whl
import in your code by
import pyfftw as fftw

Why I can not use an installed module for python?

I have installed a python library MySQLdb, and it works yesterday. But today when I tried to run it, it goes on as following:
czhao#opx790:~$ python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 2 2014, 12:34:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
It is really strange, so I try to re-install it, but it seems I do have the library in my computer:
czhao#opx790:~$ sudo apt-get install python-mysqldb
[sudo] password for czhao:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
The following packages were automatically installed and are no longer required:
libgooglepinyin0-dev linux-headers-3.2.0-27 linux-headers-3.2.0-41
linux-headers-3.2.0-37 linux-headers-3.2.0-43 linux-headers-3.2.0-61
patchutils linux-headers-3.2.0-37-generic linux-headers-3.2.0-27-generic
linux-headers-3.2.0-61-generic linux-headers-3.2.0-43-generic dpatch
linux-headers-3.2.0-41-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
I do not know why, I have the library but python keep tell me I do not have it.
You are using Anaconda Python, but the package installed with apt-get was installed for the system Python. These two different distributions have different library directories, so packages/modules installed with one are not available for the other.
To get around this, use the pip program that came with Anaconda and run sudo pip install MySQL-python.

Unable to import praw module after install

Edit: Before you start deleting/modifying installs, please glance over StvnW's answer/summary to make sure you are applying the solution that is appropriate for you.
I've installed python 2.7.5 and pip [edit: mac OSX Mountain Lion.] I've run "pip install praw" in terminal. All good. When I run python and run "import praw" I get:
...$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named praw
...same ImportError from a script.
when I install praw I get this:
$ pip install praw
Downloading/unpacking praw
Downloading praw-2.1.10.tar.gz (83kB): 83kB downloaded
Running setup.py egg_info for package praw
Requirement already satisfied (use --upgrade to upgrade): requests>=1.2.0 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): six in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): update-checker>=0.6 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): setuptools in
/usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg (from update-
checker>=0.6->praw)
Installing collected packages: praw
Running setup.py install for praw
Installing praw-multiprocess script to /usr/local/bin
Successfully installed praw
Cleaning up...
In python if I run help('modules') it isn't there.
Relatively new to python and I haven't been able to sort this out with google search. Any hints would be much appreciated.
Edit:
SitRep:
I've uninstalled 2.7.2, uninstalled praw, and uninstalled (homebrew) pip. I ran python 2.7.5 and it couldn't find the module (as you would suspect.) I then reinstalled pip with easy_install and now 2.7.5 is finding praw but giving this error:
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/praw/__init__.py", line 43, in <module>
from update_checker import update_check
File "/Library/Python/2.7/site-packages/update_checker.py", line 11, in <module>
from pkg_resources import parse_version as V
ImportError: No module named pkg_resources
>>>
Thanks for the help so far, the spurious install was the root of problem 1.
The solution to the final problem can be found here:
No module named pkg_resources
I wish there were some way to summarize this for future readers, but I've done so many things that I no longer recall what addressed what. I basically uninstalled everything (python 2.7.2, 2.7.5, praw, pip,) reinstalled 2.7.5 from http://python.org/download/, reinstalled pip with easy_install (and sudo command) instead of homebrew, reinstalled praw with sudo command, and followed the directions for the subsequent module error in the link above. Hope that helps. :)
The OS X system versions of Python live in /System/Library/Frameworks/Python.Framework/<verson>, each of which links to /Library/Python/<version>/site-packages. Seems like you have installed another version of python and/or pip to /usr/local, but when you invoke python you are still getting the system version.
Try this:
$ /usr/local/bin/python
>>> import praw
I'd also recommend looking into tools like pyenv and virtualenv if you are going to do any amount of work with Python. Pyenv lets you easily manage and switch between multiple versions (including micro versions x.x.3, x.x.5, etc). Virtualenv lets you create isolated Python environments where you can pin down versions of site-packages specific to a particular project.
Edit (summarizing):
sudo easy_install pip will install pip under /System/Library/Python/<version>. Calling that pip will install packages to /Library/Python/<version>/site-packages
brew install python will install a second version of python — including pip — under /usr/local/. That pip will put packages in /usr/local/lib/python<version>/site-packages/`.
One version may not see packages installed to the other.
which python and which pip are helpful for troubleshooting.
Dean's final solution above results in user packages being installed to the system site-packages.
Despite Dean's choice to update the system Python, many would advocate instead using brew, pyenv, and virtualenv to isolate oneself from the system Python.
It's strange. I am suspecting you have another version of python2.7 on your mac os
If you are using a mac. Check the version of python on your shell's path using which python. Then make sure that the shebang line in the script you are trying to run uses the same version of python.
In my terminal I typed
which python and got the output /usr/local/bin/python
I went to the script I was trying to run and added the following to the first line
#!/usr/local/bin/python
Then I went back to my terminal. Checked that I was in the same directory as the script I wanted to run and typed
./my_script.py
If you don't see any output at this point make sure that you have execution permission enabled for your script by typing chmod +x my_script.py in ther terminal. Then try running the script again using ./my_script.py

Categories