developer tip

Mac OS X-EnvironmentError : mysql_config not found

optionbox 2020. 8. 17. 08:46
반응형

Mac OS X-EnvironmentError : mysql_config not found


먼저, 예, 이미 본 적이 있습니다.

pip install mysql-python이 EnvironmentError와 함께 실패 : mysql_config not found

문제

Google App Engine 프로젝트에서 Django를 사용하려고합니다. 그러나 다음과 같은 이유로 서버가 제대로 시작되지 않아 시작할 수 없었습니다.

ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

나는 약간의 조사를했고 그것은 모두 내 시스템에 있지 않은 것처럼 Mysql-python을 설치해야한다는 것을 지적했습니다. 나는 실제로 그것을 제거하려고 시도했고 이것을 얻었다.

Cannot uninstall requirement mysql-python, not installed

실제로 다음을 통해 설치하려고 할 때마다 :

sudo pip install MySQL-python

다음과 같은 오류가 발생합니다.

raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

나는 이미 실행을 시도했습니다.

export PATH=$PATH:/usr/local/mysql/bin

그러나 설치 명령을 다시 실행했지만 여전히 실패했기 때문에 도움이되지 않는 것 같습니다.

어떤 아이디어?

나는 virtualenv에 있지 않습니다.


좋아, 우선, 내가 당신과 같은 페이지에 있는지 확인하겠습니다.

  • Python을 설치했습니다.
  • 당신은 brew install mysql
  • 당신은 export PATH=$PATH:/usr/local/mysql/bin
  • 그리고 마지막으로 pip install MySQL-Python(또는 pip3 install mysqlclient파이썬 3을 사용하는 경우)

모든 단계를 동일한 순서로 수행했지만 여전히 오류가 발생하면 끝까지 읽으십시오. 그러나 이러한 단계를 정확히 따르지 않았 으면 처음부터 시도해보십시오.

따라서 단계를 따랐지만 여전히 오류가 발생합니다. 시도해 볼 수있는 몇 가지 작업이 있습니다.

  1. which mysql_configbash에서 실행 해보십시오 . 아마 찾을 수 없을 것입니다. 그것이 빌드가 그것을 찾지 못하는 이유입니다. 실행을 시도 locate mysql_config하고 무엇이 돌아 오는지 확인하십시오. 이 바이너리의 경로는 셸의 $ PATH 환경 변수에 있거나 모듈의 setup.py 파일에 명시 적으로 있어야하며 해당 파일의 특정 위치에서 찾고 있다고 가정합니다.

  2. MySQL-Python을 사용하는 대신 'mysql-connector-python'을 사용해보십시오 pip install mysql-connector-python.. 이에 대한 자세한 정보는 여기여기 에서 찾을 수 있습니다 .

  3. 'mysql / bin', 'mysql_config'및 'MySQL-Python'의 위치를 ​​수동으로 찾아 $ PATH 환경 변수에 추가합니다.

  4. 위의 모든 단계가 실패하면 MacPorts를 사용하여 'mysql'을 설치해 볼 수 있습니다.이 경우 'mysql_config'파일은 실제로 'mysql_config5'라고합니다.이 경우에는 다음을 설치 한 후이 작업을 수행해야합니다 export PATH=$PATH:/opt/local/lib/mysql5/bin.. 여기에서 자세한 내용을 확인할 수 있습니다 .

참고 1 : 일부 사람들이 설치 python-devlibmysqlclient-dev도움 을 요청하는 것을 보았지만 이러한 패키지가 Mac OS에서 사용 가능한지 모르겠습니다.

참고 2 : 또한 명령을 루트로 실행 해보십시오.

나는 (내 두뇌 외에) 다음 장소에서 내 대답을 얻었습니다 (아마도 도움이되는지 확인하기 위해 그들을 볼 수 있습니다) : 1 , 2 , 3 , 4 .

도움이 되었기를 바라며이 방법이 효과가 있는지 여부를 알게되어 기쁩니다. 행운을 빕니다.


나는이 문제를 영원히 디버깅하고 있었다-3 시간 17 분. 특히 나를 짜증나게 한 것은 이전의 Uni 작업을 통해 이미 시스템에 SQL이 설치되었지만 pip / pip3가 인식하지 못했다는 것입니다. 위의 스레드와 내가 인터넷을 샅샅이 뒤진 많은 다른 스레드는 문제를 밝히는 데 도움이되었지만 실제로는 문제를 해결하지 못했습니다.

대답

Pip은 Macintosh HD @ 에 상대적인 Homebrew 디렉토리에서 mysql 바이너리를 찾고 있습니다.

/usr/local/Cellar/

그래서 몇 가지 변경이 필요하다는 것을 알았습니다.

1 단계 : 아직 다운로드하지 않은 경우 MySql을 다운로드합니다. https://dev.mysql.com/downloads/

2 단계 : Macintosh HD 및 CD와 관련하여 찾기

/usr/local/mysql/bin

3 단계 : 일단 터미널을 열고 원하는 텍스트 편집기를 사용합니다.-저는 neovim 사람이므로 직접 입력했습니다 (Mac과 함께 자동으로 제공되지 않습니다 ... 다른 하루 동안 다른 이야기).

nvim mysql_config

4 단계 : 약 112 번 라인에서 볼 수 있습니다.

# Create options 
libs="-L$pkglibdir"
libs="$libs -l "

로 변경

# Create options 
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"

*이 파일에는 읽기 전용 액세스 권한이 있으므로 vim 또는 neovim을 사용하는 경우

:w !sudo tee %

5 단계 : 홈 디렉토리로 이동하여 .bash_profile 파일을 편집합니다.

cd ~

그때

nvim .bash_profile

추가

export PATH="/usr/local/mysql/bin:$PATH"

파일에 저장 한 다음

6 단계 : Macintosh HD와 관련 하여 경로 찾기 및 추가

cd /private/etc/

그때

nvim paths

추가

/usr/local/mysql/bin

*이 파일에 읽기 전용 액세스 권한이 있음을 다시 알 수 있으므로 vim 또는 neovim을 사용하는 경우

:w !sudo tee % 

그때

cd ~

그런 다음 다음을 실행하여 변경 사항으로 터미널을 새로 고칩니다.

source .bash_profile

드디어

pip3 install mysqlclient

그리고 비올라. 바이브라는 것을 기억하십시오.


또한 이것은 mysqlclient를 설치할 때 발생합니다.

$ pip install mysqlclient

user3429036이 말했듯이,

$ brew install mysql

If you don't want to install full mysql, we can fix this by just installing mysqlclient brew install mysqlclient Once cmd is completed it will ask to add below line to ~/.bash_profile:

echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile

Close terminal and start new terminal and proceed with pip install mysqlclient


This answer is for MacOS users who did not install from brew but rather from the official .dmg/.pkg. That installer fails to edit your PATH, causing things to break out of the box:

  1. All MySQL commands like mysql, mysqladmin, mysql_config, etc cannot be found, and as a result:
  2. the "MySQL Preference Pane" fails to appear in System Preferences, and
  3. you cannot install any API that communicates with MySQL, including mysqlclient

What you have to do is appending the MySQL bin folder (typically /usr/local/mysql/bin in your PATH by adding this line in your ~/.bash_profile file:

export PATH="/usr/local/mysql/bin/:$PATH"

You should then reload your ~/.bash_profile for the change to take effect in your current Terminal session:

source ~/.bash_profile

Before installing mysqlclient, however, you need to accept the XcodeBuild license:

sudo xcodebuild -license

Follow their directions to sign away your family, after which you should be able to install mysqlclient without issue:

pip install mysqlclient

After installing that, you must do one more thing to fix a runtime bug that ships with MySQL (Dynamic Library libmysqlclient.dylib not found), by adding this line to your system dynamic libraries path:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH


Install brew or apt-get is also not easy for me so I downloaded mysql via: https://dev.mysql.com/downloads/connector/python/, installed it. So I can find mysql_config int this directory: /usr/local/mysql/bin

the next step is:

  1. export PATH=$PATH:/usr/local/mysql/bin
  2. pip install MySQL-python==1.2.5

참고URL : https://stackoverflow.com/questions/25459386/mac-os-x-environmenterror-mysql-config-not-found

반응형