프린트 하기

OS환경 : Windows 10 pro (64bit)

 

개발 환경 : Python 3.11

 

에러 : pip install SyntaxError: invalid syntax

파이썬 라이브러리 설치시 발생하는 오류

C:\Users\test>python
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> pip install beautifulsoup4
  File "<stdin>", line 1
    pip install beautifulsoup4
        ^^^^^^^
SyntaxError: invalid syntax
>>>

 

 

해결 방법 : 파이썬 interpreter 내에서 실행하지 말고 밖에서 실행

파이썬 interpreter 에서 exit()로 나와서 cmd에서 실행

>>> exit()
C:\Users\test>pip install beautifulsoup4
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.11.1-py3-none-any.whl (128 kB)
     ---------------------------------------- 128.2/128.2 kB 7.9 MB/s eta 0:00:00
Collecting soupsieve>1.2
  Downloading soupsieve-2.3.2.post1-py3-none-any.whl (37 kB)
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.11.1 soupsieve-2.3.2.post1

정상적으로 설치됨

 

 

원인 : 잘못된 곳에서 pip 명령 실행

pip는 Python 패키지를 관리할 수 있는 명령줄 도구임

그렇기 때문에 Python 인터프리터에서 직접 액세스할 수는 없음
Python 인터프리터에서 ls -la 명령을 입력하는것과 같은 맥락

오라클로 치면 sqlplus 안에서 ls -al 명령을 입력하는것과 같은 맥락

 

 

참조 : https://linuxhint.com/pip-install-invalid-syntax/