如何将 export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH 加入虚拟环境变量
时间: 2023-12-13 13:02:45 浏览: 41
你可以在虚拟环境的 `bin/activate` 脚本中添加这个命令,这样每次激活虚拟环境时都会自动执行这个命令,将 `/usr/local/lib` 路径添加到 `DYLD_LIBRARY_PATH` 环境变量中。
具体操作步骤如下:
1. 打开终端,进入虚拟环境所在的目录。
2. 激活虚拟环境,例如:
```
source venv/bin/activate
```
3. 打开虚拟环境的 `bin/activate` 脚本,例如:
```
nano venv/bin/activate
```
4. 在文件的最后一行添加以下命令:
```
export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH
```
5. 保存并退出文件,例如按下 `Ctrl+X`,然后按下 `Y` 保存修改。
6. 重新激活虚拟环境,新的环境变量设置将会生效。
```
source venv/bin/activate
```
现在每次激活虚拟环境时,`/usr/local/lib` 路径都会被添加到 `DYLD_LIBRARY_PATH` 环境变量中。
相关问题
dyld[6524]: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.5.0.dylib
This error message indicates that a library required by the program couldn't be loaded because it's missing or can't be found. The library in question is libldap-2.5.0.dylib, which is part of the OpenLDAP package.
To resolve this issue, try the following steps:
1. Check if OpenLDAP is installed on your system by running `brew info openldap` in the terminal. If it's not installed, install it using `brew install openldap`.
2. Once OpenLDAP is installed, try running the program again. If you still encounter the same error, check if the library file exists in the specified location using `ls -l /usr/local/opt/openldap/lib/libldap-2.5.0.dylib`. If it doesn't exist, try reinstalling OpenLDAP.
3. If the library file exists, you may need to update the library path to include the location of the library. You can do this by adding the following line to your shell profile (e.g., ~/.bash_profile or ~/.zshrc): `export DYLD_LIBRARY_PATH=/usr/local/opt/openldap/lib:$DYLD_LIBRARY_PATH`.
4. After adding the library path, run `source ~/.bash_profile` or `source ~/.zshrc` to apply the changes. Then try running the program again.
If none of the above steps work, you may need to seek further assistance from the developer or support team of the program you're trying to run.
ImportError: dlopen(/Users/cc/python_envs/envname_01_cheoa_pc_test/lib/python3.9/site-packages/pyodbc.cpython-39-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib Referenced from: <9820BF4A-872E-3566-A1CA-2902C9CCBCE4> /Users/cc/python_envs/envname_01_cheoa_pc_test/lib/python3.9/site-packages/pyodbc.cpython-39-darwin.so Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file, not in dyld cache)
这个错误提示表明 pyodbc 在加载 `libodbc.2.dylib` 库时失败了,因为找不到这个库文件。要解决这个问题,你需要检查以下几点:
1. 确认你已经正确安装了 unixODBC 库。
2. 检查 `libodbc.2.dylib` 库文件是否存在于 `/usr/local/opt/unixodbc/lib/` 目录中。如果不存在,可能是由于 unixODBC 安装不完整或者未安装导致的。你可以尝试重新安装 unixODBC 库,或者手动下载 `libodbc.2.dylib` 库文件,并将其放置到 `/usr/local/opt/unixodbc/lib/` 目录中。
3. 确认你的系统环境变量中是否包含了 unixODBC 库的路径。你可以使用以下命令检查:
```
echo $DYLD_LIBRARY_PATH
```
如果输出结果中不包含 `/usr/local/lib` 路径,可以尝试将其添加到环境变量中:
```
export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH
```
然后重新加载环境变量:
```
source ~/.bash_profile
```
4. 如果你在虚拟环境中运行代码,你需要确保在虚拟环境的 `bin/activate` 脚本中也添加了上述命令,将 `/usr/local/lib` 路径添加到 `DYLD_LIBRARY_PATH` 环境变量中。
如果你按照上述步骤仍然无法解决问题,你可以尝试重新安装 pyodbc 库,或者在 Stack Overflow 等技术社区上寻求帮助。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)