xlrd import issue with Python 2.7

后端 未结 7 1084
不思量自难忘°
不思量自难忘° 2020-12-31 07:35

I have an assignment to read excel data in Python. I have Python 2.7 installed. I tried installing xlrd0.8.0 with the following commands in Windows.

C:\\Pyth         


        
相关标签:
7条回答
  • 2020-12-31 07:52

    Resolving issue with xlrd import in Python 2.7

    open this link https://bootstrap.pypa.io/get-pip.py and save as get-pip.py and copy this file into C:\Python2.7\

    C:\Python2.7\python.exe get-pip.py
    

    After this pip is installed in your system now installing xlrd

    C:\Python2.7\python.exe -m pip install xlrd
    

    Open python and import xlrd

    import xlrd
    

    it will work.

    0 讨论(0)
  • 2020-12-31 07:52

    python -m pip install xlrd

    For my case I have both python2 and python3 installed, pip install xlrd default install xlrd into the Python3 library (/usr/local/lib/python3.6/site-packages/xlrd/. By specifying python2 for pip install solved my problem.

    0 讨论(0)
  • 2020-12-31 07:59

    For me, running python in spyder on a mac, it didn't work even after I installed xlrd using pip, because it was installed to a different location than the one spyder was using. To fix this, I first found where xlrd was installed to:

    $pip install xlrd
    Requirement already satisfied: xlrd in /usr/local/lib/python2.7/site-packages
    

    Then copied the xlrd folder from there into where Spyder could access it:

    $cd /Applications/Spyder.app/Contents/Resources/lib/python2.7/
    $cp -r /usr/local/lib/python2.7/site-packages/xlrd.
    

    Then updated the module within spyder, but I'm not sure whether this was necessary. Restarting Spyder might have also worked after making those changes.

    0 讨论(0)
  • 2020-12-31 08:00

    Please add "C:\Python27\Lib\site-packages\" to your PYTHONPATH in your system variables.

    If there is no such SYSTEM VARIABLE, please create it:

    1. Right-click the My Computer icon on your desktop and select Properties.
    2. Click the Advanced tab, then click the Environment Variables button.
    3. Under System Variables, click New.
    4. Enter the variable name as PYTHONPATH.
    5. Enter the variable value as C:\Python27\Lib\site-packages\
    6. Click OK.
    7. Click Apply Changes.
    0 讨论(0)
  • 2020-12-31 08:00

    I had the same problem, seems like the is better if you export your xlsx to a csv file and then run the following on python

    df = pd.read_csv('FileName.csv')
    

    It should work like that. If you're using iPython or even better Jupyter then run df.head() to check if pandas reads your table properly.

    Note, I am using Ubuntu

    0 讨论(0)
  • 2020-12-31 08:01

    How to reproduce and fix this error:

    Open the python interpreter, try to import xlrt, you get an error:

    python
    >>> import xlrt
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named xlrt
    

    1. Install, or make sure pip is installed:

    What is the official "preferred" way to install pip and virtualenv systemwide?

    2. Install xlrd

    pip install xlrd
    

    Protip: If you feel you have to use sudo pip install .... to get this to work then you need to stop and learn why this is dangerous. See: What are the risks of running 'sudo pip'?

    Workarounds are to install pip using a certain user: pip install --user myuser ... use your own best judgment here. Make sure the directory your pip is operating in is owned by the user trying to install packages there. Use: chown -R $USER /Library/Python/2.7/site-packages.

    3. Test it on the python interpreter:

    python
    >>> import xlrd
    
    >>> type(xlrd)
    <type 'module'>
    >>>
    

    Now it is imported it without a problem, xlrd is a python module.

    Troubleshooting:

    If your PYTHONPATH is not defined, you should define it:

    PYTHONPATH=:/home/el/wherever/where_to_find_modules
    
    0 讨论(0)
提交回复
热议问题