You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:导入Session模块失败及coinmarketcap导入报错问题

Alright, let's tackle these two Python import errors you're facing—they're both pretty common issues once you know where to look. Here's how to fix each one:

1. ImportError: cannot import name 'Session' with requests

This error usually boils down to one of three easy-to-fix problems:

  • You have a local file named requests.py
    If you accidentally created a file called requests.py in your project folder, it'll override the official requests library when you try to import. Rename that file right away (and delete any requests.pyc file that might have popped up too—those are cached bytecode files).
  • Your requests version is way too old
    The Session class has been part of requests for ages, but if you're running a super outdated version (pre-2.0.0), it might not exist. Check your current version with:
    pip show requests
    
    If it's old, update it using:
    pip install --upgrade requests
    
  • Your requests installation is corrupted
    Sometimes files get messed up during installation. Uninstall and reinstall the library to fix this:
    pip uninstall requests -y
    pip install requests
    

2. Import error with the coinmarketcap library

Looking at your traceback, the error comes from the library's core.py file. Here's what's likely going on:

  • Python 3.6 is no longer supported
    You're using Python 3.6, which reached end-of-life years ago. The older coinmarketcap package on PyPI hasn't been updated in a long time and probably doesn't work with 3.6 anymore. If you can, upgrade to a supported Python version (3.8 or newer is recommended).
  • You're using an unmaintained library
    The original coinmarketcap PyPI package is abandoned. Instead, use the official CoinMarketCap API wrapper called python-coinmarketcap. First, remove the old package:
    pip uninstall coinmarketcap -y
    
    Then install the official one:
    pip install python-coinmarketcap
    
    Adjust your import code to match the new wrapper:
    from coinmarketcap import CoinMarketCap
    # You'll need an API key from CoinMarketCap's website
    cmc = CoinMarketCap('your_api_key')
    
  • Missing or incompatible dependencies
    If you really need to stick with the old library, check its requirements.txt file (you can find it on the package's GitHub repo) and install exact versions of dependencies that work with Python 3.6. For example, it might require an older requests version like requests==2.20.0.

内容的提问来源于stack exchange,提问作者hack-is-art

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:46:38