Imports working with raw file, but not in IDLE

后端 未结 2 1109
南方客
南方客 2021-01-23 21:15

UPDATE 10 Secs later
Fixed properly now, and thanks to JF and Gauden.

UPDATE
I have found a temporary fix by saving the IDLE fi

2条回答
  •  野性不改
    2021-01-23 22:01

    I had the same problem when trying to import a newly installed library on my Raspberry Pi. I followed all the instructions to install the library (Adafruit RHT Sensor) and it worked fine from the terminal. However, I couldn't get it to work from within IDLE.

    It turned out that the problem was that the Raspberry Pi has both Python 2 and 3 installed. The install I'd done (using the 'python' command) only applied to Python 2. I had to perform another install using the 'python3' command to install it for Python 3. After that, I restarted IDLE and all worked fine.

    The suggestion above to print the sys executable path helped point out the discrepancy:

    import sys
    print sys.executable
    

提交回复
热议问题