简体   繁体   中英

Import error with module in Python 2.7

I've spent the better part of an afternoon trying to import the xlrd module, it works when i do it in the shell but when i try to run any file I get an import error. Please could somebody provide a solution? (I'm a beginner, so please be excruciatingly specific)

This code:

#!/usr/bin/python

import os

os.chdir("C:/Users/User/Documents/Python/xlrd")

import xlrd

returns the error:

Traceback (most recent call last):

   File "C:\Users\User\Documents\Python\Programs\Radiocarbon27.py", line 4 in <module>

import xlrd
ImportError: No module named xlrd

The path of the setup.py which contains the setup.py file is C:\\Users\\User\\Documents\\Python\\xlrddocs

thanks!

Click the Start button , click All Programs , click Accessories , and then click Command Prompt .

Type Python then hit enter.

If you get the following, then you have to setup your environment variables.

'python' is not recognized as an internal or external command,
    operable program or batch file.

If Python started, then you do not have to setup your environment variables. Close the command prompt and open another one.

In the new command prompt type: cd C:\\Users\\User\\Documents\\Python\\xlrddocs

Then type: Python setup.py install

That's it! Now in your .py file type:

import os
import xlrd

The xlrd package is not installed. For example, you can do

$yum install python27_xlrd-0.9.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM