Python Forum
ModuleNotFound error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: ModuleNotFound error (/thread-20287.html)

Pages: 1 2


ModuleNotFound error - HawkeyeKnight - Aug-03-2019

I am a beginner Python student, teaching myself and using the Head First Python book as a guide. I am running Python on a Windows 10 machine using Python 3.7. I am working a section where you need to import from a distribution package called vsearch that you previously created. However, whenever I try to run the code, I get a "ModuleNotFound" error.

My first assumption was that I had not gotten the site-packages location into the Path correctly. I had previously added the site-packages location into Path through the Windows change environment variables module, but thought I had perhaps made an error. I first checked to be sure that Python was looking in the right place, so I ran the command "py -m pip show vsearch", which correctly identified the directory where the vsearch package was located. I then opened Python and ran "import sys" and then "sys.path" to check that the site-packages location was in Path. It showed that the site-packages directory was in the Path that Python was checking.

At this point, I am not sure what to do next. The only thing that I am not sure about is that in the site-packages directory, the vsearch folder name is "vsearch-1.0-py3.7-egg.info". If this is correct, then I am at a loss as to why Python continues to report a ModuleNotFound error when I try to import from vsearch. Any assistance greatly appreciated.


RE: ModuleNotFound error - Larz60+ - Aug-03-2019

you need to install the module.
form command line, type:
pip -V
if it shows python 3.7.1, then type:
pip install vsearch
otherwise
pip3 install vsearch



RE: ModuleNotFound error - HawkeyeKnight - Aug-03-2019

I did install the module, sorry if that was not clear in the description - that is what I meant by "previously created"


RE: ModuleNotFound error - Larz60+ - Aug-04-2019

I don't think it's installed where you think it is.
Each python version has it's own pip.
you can list what's installed with version of pip with pip list
so find the pip associated with your install pip or pip3 or whatever
and run a list.
If you don't see vsearch where expected, it will need to be installed again


RE: ModuleNotFound error - HawkeyeKnight - Aug-04-2019

First, my thanks for your efforts to assist me with this issue, I do appreciate it!! I went back and ran pip list and vsearch is listed as an installed module. Just to be sure, tried re-installing it and tried again, no change, still get the "ModuleNotFoundError".

Thinking there might be an issue with the installation of the 64 bit Python 3.7 I was using, I went back and uninstalled it and reinstalled Python 3.7 32 bit. I then reinstalled flask, reinstalled vsearch, verified its location with pip list, and rechecked to make sure the site-packages location was in Path -all good. Tried running the program again and still get the "NoModulesFoundError".


RE: ModuleNotFound error - snippsat - Aug-04-2019

There is something wrong with there package vsearch from PyPi.
So pip install vsearch work,but import vsearch do not work.

I guess in the book they create it from setup.py as a exercise.
Just skip this part,if want a long tutorial about this i have one here.


RE: ModuleNotFound error - HawkeyeKnight - Aug-04-2019

Thanks for the heads up that vsearch does not work,otherwise would have kept looking in vain for a solution. I will move on. Unfortunately, they use it again in the next chapter, but will just skip actually running the code.


RE: ModuleNotFound error - snippsat - Aug-05-2019

(Aug-04-2019, 09:43 PM)HawkeyeKnight Wrote: Thanks for the heads up that vsearch does not work,otherwise would have kept looking in vain for a solution. I will move on. Unfortunately, they use it again in the next chapter, but will just skip actually running the code.
Can make it work for Python 3.7 i looked for code on web,so to not call it the same vvsearch.
# vvsearch.py
def search4vowels(phrase: str) -> set:
    vowels = set('aeiou')
    return vowels.intersection(set(phrase))

def search4letters(phrase: str, letters: str) -> set:
    return set(letters).intersection(set(phrase))

if __name__ == '__main__':
    print(search4letters('hitch-hiker', 'aeiou'))
    print(search4letters('galaxy', 'xyz'))
    print(search4letters('life, the universe, and everything', 'o'))
# setup.py
from setuptools import setup

setup(
   name="vvsearch",
   version='1.0',
   py_modules=['vvsearch'],
   description="Search Tool",
   url='https://python-forum.io/index.php',
   author_email='[email protected]',
)
Both files in same folder,run python setup.py bdist_wheel
In dist folder install the wheel with pip.
# Test pip
E:\div_code\my_env\
λ pip -V
pip 19.2.1 from c:\python37\lib\site-packages\pip (python 3.7)

# Install
E:\div_code\my_env\dist
λ pip install vvsearch-1.0-py3-none-any.whl
Processing e:\div_code\my_env\dist\vvsearch-1.0-py3-none-any.whl
Installing collected packages: vvsearch
Successfully installed vvsearch-1.0
Now test that it work.
E:\div_code\my_env\
λ ptpython
>>> import vvsearch

>>> vvsearch.search4letters('hitch-hiker', 'aeiou')
{'i', 'e'}
>>> vvsearch.search4letters('hello', 'aeiou')
{'o', 'e'}



RE: ModuleNotFound error - HawkeyeKnight - Aug-07-2019

Wow, that worked! I did have to change one command to "python setup.py sdist bdist_wheel", but otherwise (after I fixed three typos in the code), it all worked perfectly. Thanks so much for pursuing this for me!!


RE: ModuleNotFound error - snippsat - Aug-08-2019

(Aug-07-2019, 04:47 PM)HawkeyeKnight Wrote: Wow, that worked! I did have to change one command to "python setup.py sdist bdist_wheel"
Remember to first do pip install wheel.
Then use only python setup.py bdist_wheel
It's more flexible than sdist(source distribution).