marklar
marklar

Reputation: 123

Changing from Python 2 to 3

So I am brand new to python. I am following tutorials on it but it appears the tutorial i am using is python 2. I figured I would try to change the code to python 3. I am getting errors on the import praw. When I ran this in python 2 no problems but now after the changes and trying to run in python 3 it says praw module doesn't exist. Python 2.7 found it. I just tried upgrading it. What am I missing? here's my code:

Python:

import praw
import config
import time

example_list = ["test", "hello","123", 0]
example_list.append(32.10)
print(example_list)

def bot_login():
    print("Logging in...")
    r = praw.Reddit(username = config.username,
            password = config.password,
            client_id = config.client_id,
            client_secret = config.client_secret,
            user_agent = "i_am_learning_bot's dog comment responder v.01")
    print("logged in!")

    return r

def run_bot(r):
    print("Obtaining 25 comments...")
    for comment in r.subreddit('test').comments(limit=25):
        if "dog" in comment.body:
            print("String with \"dog\" found in comment " + comment.id)
            comment.reply("Ohh dogs? I also love dags! [Here](http://i.imgur.com/LLgRKeq.jpg) is an image of one.)")
            print ("Replied to comment" + comment.id)
    print("Sleeping for 10 seconds...")
    #sleep for 10 seconds...
    time.sleep(10)

#r = bot_login()
#while True:
#    run_bot(r)

Upvotes: 1

Views: 105

Answers (3)

pr0grammaniac
pr0grammaniac

Reputation: 11

You should go for smt like:

pip3 install praw

Because python3.x and 2.x do not share same packages.. Good luck bro!

Upvotes: 0

Yilun Zhang
Yilun Zhang

Reputation: 9018

The python packages are associated with python versions. The praw package is only installed for Python 2 but NOT for Python 3.

Depending on how you installed your python 3, you will need to install the praw package. For example, do pip3 install praw, conda install praw, etc.

Upvotes: 0

Aaron Christiansen
Aaron Christiansen

Reputation: 11837

Your code is probably fine, but pip modules aren't shared between Python versions. If you have Python 2 and Python 3 installed, then you usually need to use pip3 to install packages for Python 3. Just pip will install Python 2 packages.

This means that you need to execute the following command in your terminal:

pip3 install praw

Upvotes: 2

Related Questions