-1

I'm developing an application which interacts with raspberry pi.I need to get the temperature and humidity sensor readings from raspberry pi, for that I wrote this code.(I'm using python 2.7)

import RPi.GPIO as GPIO
import dht11
import time
import datetime

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 4
instance = dht11.DHT11(pin=4)


result = instance.read()
if result.is_valid():
    #print("Last valid input: " + str(datetime.datetime.now()))
    print("Temperature: %d C" % result.temperature)
    print("Humidity: %d %%" % result.humidity)
else:
    print "invalid"

But the problem is I can't add RPi.GPIO library to Pycharm, It's available in python Interpreter page but couldn't download to the IDE.So I downloaded it from https://pypi.python.org/pypi/RPi.GPIO page then I didn't find any tutorial on how to add it to the IDE, can anyone please help me.

swtCode
  • 1
  • 1
  • 1
  • 1
  • I recommend against the DHT11, it is a bad sensor, even if you calibrate it it’s unreliable. Try the DHT22 instead. – user2497 Sep 24 '17 at 12:02

1 Answers1

1

You should be able to run

pip install --user RPi.GPIO

in the terminal window inside pycharm.

However before you do that I would recommend using a python virtual environment for the project. To do this you need to edit the project interpreter and:

  • Click on the Gear Icon at the top right of the window.
  • There is an option in there called: Create VirtualEnv
  • Select your preferred Python version.
  • Give the Virtual Env a name and click OK out of that window and the Settings window.

If you do end up using a Virtual Env, the pip command should be run without the user flag:

pip install RPi.GPIO

A much more thorough walk through of the process can be found here: Configuring Python virtual environment

flynnstone
  • 96
  • 3