Why does “pip install” inside Python raise a SyntaxError?

后端 未结 8 843
天命终不由人
天命终不由人 2020-11-21 05:46

I\'m trying to use pip to install a package. I try to run pip install from the Python shell, but I get a SyntaxError. Why do I get this error? H

相关标签:
8条回答
  • 2020-11-21 06:09

    Programmatically, the following currently works. I see all the answers post 10.0 and all, but none of them are the correct path for me. Within Kaggle for sure, this apporach works

    from pip._internal import main as _main
    
    package_names=['pandas'] #packages to install
    _main(['install'] + package_names + ['--upgrade']) 
    
    0 讨论(0)
  • 2020-11-21 06:12

    pip is run from the command line, not the Python interpreter. It is a program that installs modules, so you can use them from Python. Once you have installed the module, then you can open the Python shell and do import selenium.

    The Python shell is not a command line, it is an interactive interpreter. You type Python code into it, not commands.

    0 讨论(0)
  • 2020-11-21 06:12

    To run pip in Python 3.x, just follow the instructions on Python's page: Installing Python Modules.

    python -m pip install SomePackage
    

    Note that this is run from the command line and not the python shell (the reason for syntax error in the original question).

    0 讨论(0)
  • 2020-11-21 06:13

    Use the command line, not the Python shell (DOS, PowerShell in Windows).

    C:\Program Files\Python2.7\Scripts> pip install XYZ
    

    If you installed Python into your PATH using the latest installers, you don't need to be in that folder to run pip

    Terminal in Mac or Linux

    $ pip install XYZ
    
    0 讨论(0)
  • 2020-11-21 06:14

    Try upgrade pip with the below command and retry

    python -m pip install -U pip
    
    0 讨论(0)
  • 2020-11-21 06:16

    you need to type it in cmd not in the IDLE. becuse IDLE is not an command prompt if you want to install something from IDLE type this

    >>>from pip.__main__ import _main as main
    >>>main(#args splitted by space in list example:['install', 'requests'])
    

    this is calling pip like pip <commands> in terminal. The commands will be seperated by spaces that you are doing there to.

    0 讨论(0)
提交回复
热议问题