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'
>>> 
Asked By: Ramy

||

Answers:

You must install this module for python3.

Python modules, libraries are different for python 2 and 3.

Answered By: Carlos Afonso

Try this command if you have pip3

pip3 install ply

This works too:

python3 -m pip install ply
Answered By: Gribouillis

for linux installation:

python 2.7.x : sudo apt-get install python-ply

python 3.x : sudo apt-get install python3-ply

https://www.howtoinstall.co/en/ubuntu/utopic/python-ply

Answered By: f.marsit

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.

  1. Install ply library

    pip3 install ply
    this would show you where the library is stored after successful installation.

  2. Go to the location and make your project their.

This worked for me. Hopefully it would help you too.

Answered By: Syed Bilal Haider
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.