Why is python3 not finding a module?
Question:
Running my script (which imports ply) with python 2.7 works without issue. But trying to run the same script with python3 causes the following. (Note: I’m on v3.10 of ply – the latest which should be compatible with python3).
bos-mpqpu:config_parse rabdelaz$ python3 lexparse.py
Traceback (most recent call last):
File "lexparse.py", line 1, in <module>
import ply.lex as lex
ModuleNotFoundError: No module named 'ply'
bos-mpqpu:config_parse rabdelaz$ pip show ply | grep Version
Version: 3.10
I’ve installed python3:
bos-mpqpu:config_parse rabdelaz$ python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ply
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ply'
>>>
Answers:
You must install this module for python3.
Python modules, libraries are different for python 2 and 3.
Try this command if you have pip3
pip3 install ply
This works too:
python3 -m pip install ply
for linux installation:
python 2.7.x : sudo apt-get install python-ply
python 3.x : sudo apt-get install python3-ply
I was facing the same issue but couldn’t exactly know what was the problem so I again installed ply library and went to its location and made my project there. Library worked well there.
-
Install ply library
pip3 install ply
this would show you where the library is stored after successful installation.
-
Go to the location and make your project their.
This worked for me. Hopefully it would help you too.
Running my script (which imports ply) with python 2.7 works without issue. But trying to run the same script with python3 causes the following. (Note: I’m on v3.10 of ply – the latest which should be compatible with python3).
bos-mpqpu:config_parse rabdelaz$ python3 lexparse.py
Traceback (most recent call last):
File "lexparse.py", line 1, in <module>
import ply.lex as lex
ModuleNotFoundError: No module named 'ply'
bos-mpqpu:config_parse rabdelaz$ pip show ply | grep Version
Version: 3.10
I’ve installed python3:
bos-mpqpu:config_parse rabdelaz$ python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ply
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ply'
>>>
You must install this module for python3.
Python modules, libraries are different for python 2 and 3.
Try this command if you have pip3
pip3 install ply
This works too:
python3 -m pip install ply
for linux installation:
python 2.7.x : sudo apt-get install python-ply
python 3.x : sudo apt-get install python3-ply
I was facing the same issue but couldn’t exactly know what was the problem so I again installed ply library and went to its location and made my project there. Library worked well there.
-
Install ply library
pip3 install ply
this would show you where the library is stored after successful installation. -
Go to the location and make your project their.
This worked for me. Hopefully it would help you too.