简体   繁体   中英

Python 2.7 import ConfigParser ModuleNotFoundError: No module named 'ConfigParser'

so lately i have a project to make a cryptocurrency trading bot using Python and then i stumble across Cointrader Library for Python, so i use that library for helping me build this project, the exchanger used here was Poloniex, so i added Poloniex API Keys and Secrets but then when i run one of the comment that was showed buy the Cointrader Library which is to check balance (using cmd and typed in (cointrader balance) theres an error that i stumble upon, and i dont know how to fix it, ive been searching for the error for hours and still cant find it, i really need your help, thankyou community :)

this are the Python code that i use

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import logging
import logging.config
import six
import ConfigParser

DEFAULT_CONFIG = ".cointrader.ini"


def get_path_to_config():
    env = os.getenv("HOME")
    return os.path.join(env, DEFAULT_CONFIG)


class Config(object):

    def __init__(self, configfile=None):

        self.verbose = False
        self.market = "poloniex"
        self.api_key = None
        self.api_secret = None

        if configfile:
            logging.config.fileConfig(configfile.name)
            config = ConfigParser()
            config.readfp(configfile)
            exchange = config.get("DEFAULT", "exchange")
            self.api_key = config.get(exchange, "api_key")
            self.api_secret = config.get(exchange, "api_secret")

    @property
    def api(self):
        if not self.api_key or not self.api_secret:
            raise RuntimeError("API not configured")
        return self.api_key, self.api_secret

so that is the Python Code and this is the Error that i get when i run (cointrader balance) in cmd

C:\Users\user>cointrader balance
Traceback (most recent call last):
  File "c:\users\user\appdata\local\programs\python\python36\lib\runpy.py", 
line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\user\appdata\local\programs\python\python36\lib\runpy.py", 
line 85, in _run_code
    exec(code, run_globals)
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python36\Scripts\
cointrader.exe\__main__.py", line 5, in <module>
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-
packages\cointrader\cli.py", line 7, in <module>
    from cointrader.config import Config, get_path_to_config
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-
packages\cointrader\config.py", line 7, in <module>
    import ConfigParser
ModuleNotFoundError: No module named 'ConfigParser'

C:\Users\user>

that is the message that i get from CMD when i try to run "cointrader balance" which should show My Balance in Poloniex... please i really need your guys help, i really dont know what the problem is, you can check the cointrader library here: https://pypi.python.org/pypi/cointrader

thankyou so much for your help :-)

With @Klaus D's comment in mind:

Since you are using Windows, you'd need to specify the Python executable to be use. Ie C:\\Programfiles\\Python2.7\\Python.exe myscript.py

This could be done by way of a manually typed in command, .bat file or making a shortcut/icon on desktop that specifies the Python.exe to be used. (sorry if i'm incorrect, it's been a few years since i last used windows)

For another alternative, setting the python 2.7 exe as an alias , see https://superuser.com/a/560558/633849

Also, if i remember correctly; When installing Python to windows, the installers offers a checkbox option to whether or not to make that specific version/installation the default python command.

It shouldn't be a problem having multiple versions of Python installed on Windows as well.. The only difference would be the folder of the Python.exe . Pretty sure you'll find a Python3.6 or Python3 folder in your C:\\Programfiles\\

(If on Linux however: To run it using Python 2.7 instead of what i would assume is the default Python 3.6 installation on your system; Instead of using python myscript.py , use python2.7 myscript.py )

(This of course all relies on python 2.7 actually being installed)

为了创建ConfigParser对象,您应该只编写: config = ConfigParser而不是: config = ConfigParser() ,这使它在解释器中对我config = ConfigParser()

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