Ubuntu python 软链接或调用pip有问题

在使用ubuntu时有时会用到docker比如tensorflow跟PyTorch的官方镜像。但有时会遇到无法直接调用python,或者调用pip有问题,这是因为 docker 镜像默认没有把 python 软链接。

这时我们需要

whereis python

把本机上所有的 python 列举出来。

例如 pytorch/pytorch:1.7.0-cuda11.0-cudnn8-devel 显示是

root@6d0dd29bd661:# whereis python python:/opt/conda/bin/python3.8/opt/conda/bin/python /opt/conda/bin/python3.8-config

那么python的路径就是在 /opt/conda/bin/python3.8 这里,接下来我们只需要

IS

/opt/conda/bin/python3.8

即可。

显示例子:

root@6d0dd29bd661:#Is

root@6dedd29bd661:#/opt/conda/bin/python3.8

Python 3.8.3(default, May 19 2020,18:47:26)

[ GCC 7.3.0]:: Anaconda, Inc. on linux Type "help","copyright","credits"or "license"for more information.

>>>import torch

然后软连接的方式是:

echo "export PATH=\"/opt/conda/bin:\$PATH\"">>/root/.bashrc && source /root/.bashrc

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容