【问题标题】:Python: can't upgrade pip to version 9.0.1 (spyder)Python:无法将 pip 升级到版本 9.0.1 (spyder)
【发布时间】:2017-07-31 15:31:55
【问题描述】:

我一直在尝试为 python 安装一些软件包,例如 pygame 和 metatrader。当我尝试时,它会被要求升级我的版本。 当我尝试这样做时,会发生以下情况

C:\Users\USER>pip install --upgrade pip
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
Exception:
Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\shutil.py", line 538, in move
    os.rename(src, real_dst)
PermissionError: [WinError 5] Toegang geweigerd: 'c:\\programfiles\\anaconda3\\lib\\site-packages\\pip' -> 'C:\\Users\\USER\\AppData\\Local\\Temp\\pip-46ifh8km-uninstall\\program files\\anaconda3\\lib\\site-packages\\pip'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\commands\install.py", line 317, in run
prefix=options.prefix_path,
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\req\req_set.py", line 736, in install
requirement.uninstall(auto_confirm=True)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\req\req_install.py", line 742, in uninstall
paths_to_remove.remove(auto_confirm)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\req\req_uninstall.py", line 115, in remove
renames(path, new_path)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\utils\__init__.py", line 267, in renames
shutil.move(old, new)
  File "C:\Program Files\Anaconda3\lib\shutil.py", line 550, in move
rmtree(src)
  File "C:\Program Files\Anaconda3\lib\shutil.py", line 488, in rmtree
return _rmtree_unsafe(path, onerror)
  File "C:\Program Files\Anaconda3\lib\shutil.py", line 383, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Program Files\Anaconda3\lib\shutil.py", line 381, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Toegang geweigerd: 'c:\\program files\\anaconda3\\lib\\site-packages\\pip\\basecommand.py'

You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

在我尝试之后,它再次给出了相同的信息。我一直在尝试为 python 安装一些软件包,例如 pygame 和 metatrader

【问题讨论】:

  • 尝试以管理员身份打开 cmd 命令提示符,然后再次尝试安装软件包。 (右键cmd.exe,选择以管理员身份运行)
  • 您是否尝试过运行 python -m pip install --upgrade pip 就像它在最后所说的那样,而不是仅仅运行 pip install --upgrade pip?
  • 是的,我有,恐怕会产生完全相同的结果。

标签: python pip upgrade spyder


【解决方案1】:

我解决了这个问题。

问题是在 spyder 中我尝试升级 pip 而不是:

conda upgrade spyder

我不得不删除完整的 anaconda 安装并重新安装。

所以永远不要尝试

pip install

在 spyder 提示符中!

【讨论】:

    【解决方案2】:

    在 linux 世界中,您需要拥有 sudo 权限才能升级 pip。 Windows 中可能也是这种情况(称为管理员权限)。 我很少在基础系统上摆弄 pip,但要么在 virtualenv 中工作,要么使用 docker 将应用程序容器化。这样你就可以在你的计算机上保持一个精简的 Python。

    【讨论】:

    • 感谢您的回答。恐怕我只是一个初学者程序员,我真的不明白如何执行你的解释? .我在其他地方读过关于 sudo 的文章,但我的命令提示符对此并不熟悉,我猜是因为我确实有 Windows
    【解决方案3】:

    我通过使用sudo权限升级pip解决了这个问题。然后它可以工作了。

    sudo pip install --upgrade pip
    

    【讨论】:

      【解决方案4】:

      python 和 metatrader 的另一个很好的解决方案,请查看:

      import socket
      import numpy as np
      import pandas as pd
      from datetime import datetime
      import pytz
      
      import io
      
      TZ_SERVER = 'Europe/Tallinn' # EET
      TZ_LOCAL  = 'Europe/Budapest'
      TZ_UTC    = 'UTC'
      
      class Pytrader_API:             
        
          def __init__(self):
              self.socket_error: int = 0
              self.socket_error_message: str = ''
              self.order_return_message: str = ''
              self.order_error: int = 0
              self.connected: bool = False
              self.timeout: bool = False
              self.command_OK: bool = False
              self.command_return_error: str = ''
              self.debug: bool = False
              self.version: str = '1.06'
              self.max_bars: int = 5000
              self.max_ticks: int = 5000
              self.timeout_value: int = 60
              self.instrument_conversion_list: dict = {}
              self.instrument_name_broker: str = ''
              self.instrument_name_universal: str = ''
              self.date_from: datetime = '2000/01/01, 00:00:00'
              self.date_to: datetime = datetime.now()
              self.instrument: str = ''
      
          def Set_timeout(self,
                          timeout_in_seconds: int = 60
                          ):
              """
              Set time out value for socket communication with MT4 or MT5 EA/Bot.
              Args:
                  timeout_in_seconds: the time out value
              Returns:
                  None
              """
              self.timeout_value = timeout_in_seconds
              self.sock.settimeout(self.timeout_value)
              self.sock.setblocking(1)
              return
      
          def Disconnect(self):
              """
              Closes the socket connection to a MT4 or MT5 EA bot.
              Args:
                  None
              Returns:
                  bool: True or False
              """
      
              self.sock.close()
              return True
      
          def Connect(self,
                      server: str = '',
                      port: int = 2345,
                      instrument_lookup: dict = []) -> bool:
              """
              Connects to a MT4 or MT5 EA/Bot.
              Args:
                  server: Server IP address, like -> '127.0.0.1', '192.168.5.1'
                  port: port number
                  instrument_lookup: dictionairy with general instrument names and broker intrument names
              Returns:
                  bool: True or False
              """
              self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              self.sock.setblocking(1)
              self.port = port
              self.server = server
              self.instrument_conversion_list = instrument_lookup
      
              if (len(self.instrument_conversion_list) == 0):
                  print('Broker Instrument list not available or empty')
                  self.socket_error_message = 'Broker Instrument list not available'
                  return False
      
              try:
                  self.sock.connect((self.server, self.port))
                  try:
                      data_received = self.sock.recv(1000000)
                      self.connected = True
                      self.socket_error = 0
                      self.socket_error_message = ''
                      return True
                  except socket.error as msg:
                      self.socket_error = 100
                      self.socket_error_message = 'Could not connect to server.'
                      self.connected = False
                      return False
              except socket.error as msg:
                  print(
                      "Couldnt connect with the socket-server: %self.sock\n terminating program" %
                      msg)
                  self.connected = False
                  self.socket_error = 101
                  self.socket_error_message = 'Could not connect to server.'
                  return False
      
          def Check_connection(self) -> bool:
              """
              Checks if connection with MT terminal/Ea bot is still active.
              Args:
                  None
              Returns:
                  bool: True or False
              """
      
              self.command = 'F000#0#'
              self.command_return_error = ''
              ok, dataString = self.send_command(self.command)
      
              try:
                  if (ok == False):
                      self.command_OK = False
                      return False
      
                  x = dataString.split('#')
      
                  if x[1] == 'OK':
                      self.timeout = True
                      self.command_OK = True
                      return True
                  else:
                      self.timeout = False
                      self.command_OK = True
                      return False
              except:
                  self.command_return_error = 'Unexpected socket communication error'
                  self.command_OK = False
                  return False
      
          @property
          def IsConnected(self) -> bool:
              """Returns connection status.
              Returns:
                  bool: True or False
              """
              return self.connected
      
          def Get_static_account_info(self) -> dict:
              """
              Retrieves static account information.
              Returns: Dictionary with:
                  Account name,
                  Account number,
                  Account currency,
                  Account type,
                  Account leverage,
                  Account trading allowed,
                  Account maximum number of pending orders,
                  Account margin call percentage,
                  Account close open trades margin percentage
              """
              self.command_return_error = ''
      
              ok, dataString = self.send_command('F001#0#')
              if (ok == False):
                  self.command_OK = False
                  return None
      
              if self.debug:
                  print(dataString)
      
              x = dataString.split('#')
              if x[0] != 'F001':
                  self.command_return_error = str(x[2])
                  self.command_OK = False
                  return None
      
              returnDict = {}
              del x[0:2]
              x.pop(-1)
      
              returnDict['name'] = str(x[0])
              returnDict['login'] = str(x[1])
              returnDict['currency'] = str(x[2])
              returnDict['type'] = str(x[3])
              returnDict['leverage'] = int(x[4])
              returnDict['trade_allowed'] = bool(x[5])
              returnDict['limit_orders'] = int(x[6])
              returnDict['margin_call'] = float(x[7])
              returnDict['margin_close'] = float(x[8])
      
              self.command_OK = True
              return returnDict
      
          def Get_dynamic_account_info(self) -> dict:
              """
              Retrieves dynamic account information.
              Returns: Dictionary with:
                  Account balance,
                  Account equity,
                  Account profit,
                  Account margin,
                  Account margin level,
                  Account margin free
              """
              self.command_return_error = ''
      
              ok, dataString = self.send_command('F002#0#')
              if (ok == False):
                  self.command_OK = False
                  return None
      
              if self.debug:
                  print(dataString)
      
              x = dataString.split('#')
              if x[0] != 'F002':
                  self.command_return_error = str(x[2])
                  self.command_OK = False
                  return None
      
              returnDict = {}
              del x[0:2]
              x.pop(-1)
      
              returnDict['balance'] = float(x[0])
              returnDict['equity'] = float(x[1])
              returnDict['profit'] = float(x[2])
              returnDict['margin'] = float(x[3])
              returnDict['margin_level'] = float(x[4])
              returnDict['margin_free'] = float(x[5])
      
              self.command_OK = True
              return returnDict
      
          def Get_PnL(self,
                          date_from: datetime = datetime(2021, 3, 1, tzinfo = pytz.timezone("Etc/UTC")),
                          date_to: datetime = datetime.now()) -> pd.DataFrame:
              '''    
              Retrieves profit loss info.
              Args:
                  date_from: start date
                  date_to: end date
              Returns: Dictionary with:
                  realized_profit             profit of all closed positions
                  unrealized_profit           profit of all open positions
                  buy_profit                  profit of closed buy positions
                  sell_profit                 profit of closed sell positions
                  positions_in_profit         number of profit positions
                  positions in loss           number of loss positions
                  volume_in_profit            total volume of positions in profit
                  volume_in_loss              total volume of positions in loss
              '''
              total_profit = 0.0
              buy_profit = 0.0
              sell_profit = 0.0
              trades_in_loss = 0
              trades_in_profit = 0
              volume_in_loss = 0.0
              volume_in_profit = 0.0
              commission_in_loss = 0.0
              commission_in_profit = 0.0
              swap_in_loss = 0.0
              swap_in_profit = 0.0
              unrealized_profit = 0.0
      

      这个例子取自Pytrader for Metatrader API

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-21
        • 2018-09-19
        • 1970-01-01
        • 1970-01-01
        • 2017-12-14
        • 2013-05-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多