Carter Michaelis
Carter Michaelis

Reputation: 275

Cannot import praw

When I try to use

import praw

I get the following error:

ModuleNotFoundError: No module named 'praw'

I made sure to install praw beforehand in the command prompt, using pip install praw, so I'm not sure why it isn't working. I'm new to programming, so any insight would be greatly appreciated.

Upvotes: 3

Views: 4738

Answers (6)

Carter Michaelis
Carter Michaelis

Reputation: 275

Thank you all so much for your help, but I have finally figured out what was causing my problem! In a separate file for the bot called requirements.txt, I had:

git+https://github.com/Rapptz/Discord.py
PyNaCl==1.3.0
pandas
dnspython==1.16.0
async-timeout==3.0.1

I simply added praw==7.2.0, and it worked! I appreciate your efforts in trying to help me :)

Upvotes: 0

Jashwanth Jase
Jashwanth Jase

Reputation: 21

I had the same problem and was looking into several ways to solve it.

For me the solution was as simple as changing the name of the pyhton file to some like "test" instead of "praw".

Yes, I named my file "praw.py" and was importing praw which was the origin of the error.

Upvotes: 2

artk
artk

Reputation: 11

If you want to use praw with python2 you'll have to use:

pip install praw

If you want to use praw with python3 you'll have to use:

pip3 install praw

Upvotes: 1

anjandash
anjandash

Reputation: 817

It depends on the python version (yours say Python3.9) in your environment.
Try pip3 to install your packages. I would open up the terminal and do the following:

$ pip3 install praw
$ python3 myscript.py

Upvotes: 3

Ajay
Ajay

Reputation: 5347

I've installed praw using pip3 install praw. So it is not showing in my system default python i.e python 2.7.17.

   cam@cam:~$ python
    Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
    [GCC 7.5.0] on linux2
    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
    >>> 
    [5]+  Stopped                 python
    cam@cam:~$ python3
    Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
    [GCC 8.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import praw

Upvotes: 1

Grace
Grace

Reputation: 335

You could very well be having an issue with multiple python installations across your system. I suggest cleaning up your environment, and using a virtual environment.

You should run the following to build a clean virtual environment in your working directory:

python -m venv venv

This will create a virtual environment which should be free of system-wide packages, and is a nice and shiny clean python installation.

Now you'll want to activate it. You said you were on Windows, so then run venv\Scripts\activate.bat if you're using CMD, or venv\Scripts\Activate.ps1 if you're using PowerShell.

Now try reinstalling praw with python -m pip install praw. You should now always be able to access praw if you're in this virtual environment.

If you're interested on reading the documentation on VirtualEnvs, here it is. You might also be interested in checking out the Hitchhiker's Guide to Python, especially the chapter on virtual environments and package management. (Do note that this last chapter uses pipenv instead of virtualenv.)

Upvotes: 2

Related Questions