1. 相关资源链接
- pypi 镜像使用帮助
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ - 临时使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade numpy
注意,这种方式有可能出现版本检查不够的情况。 - anaconda清华源
https://mirror.tuna.tsinghua.edu.cn/help/anaconda/
Anaconda 安装包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下载。
TUNA 还提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch等,查看完整列表)的镜像,各系统都可以通过修改用户目录下的.condarc
文件:
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
2. 滴滴云登录和挂载云盘
mkdir /mycloud
lsblk
sudo mount --o rw /dev/vdb1 /mycloud/
source activate py3
3. conda环境管理
- 查看环境
conda env list
- 创建环境
conda create -n python36 python=3.6
- 进入环境
source activate python36
activate python36
# windows下 - 搜索包
conda search mxnet*
- 指定环境,查看已安装的包
conda list -n python36
- 指定环境,安装指定版本的包
conda install -n python36 mxnet==1.0.0
- 指定环境,更新包
conda update -n python36 mxnet
- 指定环境,删除包
conda remove -n python36 mxnet
- 导出环境为yml
conda env export > environment.yml
- 根据yml创建环境
conda env create -f environment.yml
- 对yml文件修改后更新环境
conda env update -f environment.yml
- 退出环境
source deactivate
deactivate
# windows下 - 复制环境
conda create -n python36 --clone python36_new
- 删除环境
conda remove -n python36 --all
- 更改镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
- 修改后可以在~/.condarc配置文件中可以看到相应信息
pip修改镜像源(修改~/.pip/pip.conf配置文件)
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
4. 安装OpenCV
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python==3.3.0.10 (对应python3.6.5,python3.7应安装3.4.5.20)
5. Jupyter Notebook导入和删除虚拟环境
原文链接:https://blog.csdn.net/fengzhongluoleidehua/article/details/84614736
- 激活环境
source activate 环境名称
- 安装ipykernel
conda install ipykernel
- 将环境写入到notebook中
python -m ipykernel install --user --name 环境名称 --display-name "在notebook中显示的环境名"
- 打开notebook
note:并不一定要在conda基础环境下安装notebook,在任何一个环境中有notebook就可以了。在不同环境中需要安装ipykernel - 另外的方法
在Jupyter Notebook中加载虚拟环境,比如现在我创建了一个虚拟环境名为pytorch,那么首先我先进入虚拟环境
activate pytorch # Linux下需要使用source activate
conda install nb_conda_kernels
删除环境则调用:
jupyter kernelspec remove pytorch
附录:问题解决
1. ImportError: libSM.so.6: cannot open shared object file: No such file or directory
运行opencv的代码时,报以下错误:
Traceback (most recent call last):
File "data_generator.py", line 24, in <module>
import cv2
File "/usr/local/lib/python3.5/dist-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
解决
原因是缺少共享文件库,解决办法如下:
- 安装apt-file
# apt-get update
# apt-get install apt-file
# apt-file update
- 寻找依赖库
# apt-file search libSM.so.6
- 根据提示,安装合适的依赖库
# apt-get install libsm6
即可解决问题。
2. tensorflow-gpu==1.10
与numpy==1.18
匹配
否则出现numpy能import,但是使用时报错。
3. jupyter notebook 打开ipynb时提示到后台服务的连接没能建立, 我们会继续尝试重连, 请检出网络连接…还有服务配置 命令行显示Replacing stale connection
解决方法
把tornado降级为4.5.3
pip install tornado==4.5.3
https://github.com/jupyter/notebook/issues/2664
4. RemoveError: ‘setuptools’ is a dependency of conda and cannot be removed from conda’s operatin
https://www.cnblogs.com/hellojiaojiao/p/10872421.html
RemoveError: ‘setuptools’ is a dependency of conda and cannot be removed from
conda’s operating environment.
试了第一种方法:
pip uninstall install setuptools 然后conda install setuptools ,没有用,依然报错
第二种:
conda update conda 没用,报相同错误
第三种:
conda update --force conda,
我使用了第三种方法,仍然是报同样的错误不管用
折腾了我两三天
https://superuser.com/questions/1402260/error-when-updating-conda-packages-removeerror-setuptools-is-a-dependency-of
最终使用
conda install -c anaconda setuptools
成功安装
另外还有方法:
conda update -n base -c defaults conda setuptools
————————————————
版权声明:本文为CSDN博主「ymsg1983」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ymsg1983/article/details/91857968
5. 解决tensorflow-gpu 2.1出现错误“Could not load dynamic library ‘cudart64_101.dll’
https://blog.csdn.net/qq_41999081/article/details/104515513
最新版的tensorflow2.1默认安装cpu和gpu两个版本,gpu不能运行时退回到cpu版本。运行相关代码时显示错误:
Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
Ignore above cudart dlerror if you do not have a GPU set up on your machine.
不能运行gpu版本,简直令人抓狂。
先来排查错误,显示“cudart64_101.dll not found”,那是因为我安装的cuda为10.0版本的,“cudart64_101.dll”是cuda10.1这个版本中才含有的(cuda10.2貌似也没有)。
因此我们需要手动将“cudart64_101.dll”添加到“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin”中去。
另附cudart64_101.dll链接https://cn.dll-files.com/cudart64_101.dll.html
6. 最新的TensorFlow2.2需要VC_redist.x64.exe支持,导入tensorflow.出现importError: DLL load failed: 找不到指定的模块。python3.7
https://blog.csdn.net/sereasuesue/article/details/105327611
安装2.1.0版本程序包需要msvcp140_1.dll文件,点击上图中的Microsoft VC++ downloads下载安装包并下载,即可成功导入Tensorflow。
https://support.microsoft.com/zh-cn/help/2977003/the-latest-supported-visual-c-downloads
7. Python 从相对路径下import的方法
例如我们有如下结构的文件:
pkg/
init.py
libs/
some_lib.py
init.py
components/
code.py
init.py
如果我们想要在code.py中调用libs/some_lib.py这个module,比如使用相对调用:from …libs.some_lib import something,仅仅在package中加上__init__.py是不够的。python会返回ValueError: Attempted relative import in non-package这个错误。那么这个问题如何解决呢?
有以下解决方法:
将当前路径加入sys.path
考虑到compontent和libs是处于同一级别的文件夹,我们可以直接在code.py中加入如下代码来把当前文件夹的母文件夹加入系统路径。
import sys
from os import path
sys.path.append( path.dirname( path.dirname( path.abspath(file) ) ) )
或者如下(这种情况对任何关系的文件夹都适用,只要我们在lib_path中给出到达该文件夹的绝对路径):
import os, sys
lib_path = os.path.abspath(os.path.join(’…’))
sys.path.append(lib_path)
这样我们就可以用from libs.some_lib import something来import了。
以package模式执行该代码:
1
python -m pkg.components.code
然后我们就可以用from …libs.some_lib import something 来import了。
注意这里不需要.py作为文件结尾。
总结
我们实际上可以结合这两种方法:
if name == ‘main’:
if package is None:
import sys
from os import path
sys.path.append(
from libs.some_lib import something
else:
from …libs.some_lib import something
以上这篇Python 从相对路径下import的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
8. 关于从Windows安装Ubuntu后又卸载Ubuntu,恢复bootloader的问题
https://askubuntu.com/questions/429610/uninstall-grub-and-use-windows-bootloader
9. 关于TensorFlow2.2的版本
与cuda10.1和cudnn7.6.5匹配
10. windows下安装pycocotools
安装pycocotools
COCO 地址: https://github.com/cocodataset/cocoapi
大佬改写支持 Windows 的 COCO 地址:https://github.com/philferriere/cocoapi
方案一
CMD 终端中使用 pip 安装:
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
方案二
https://github.com/philferriere/cocoapi下载源码,并进行解压。以管理员身份打开 CMD 终端,并切换到 cocoapi\PythonAPI目录。运行以下指令:
- install pycocotools locally
python setup.py build_ext --inplace
- install pycocotools to the Python site-packages
python setup.py build_ext install
作者:oopp8
链接:https://www.jianshu.com/p/8658cda3d553
关于运行keras-retinanet的keras版本
对应keras版本可以为2.1.6或者2.2.4,应该是后面版本可用。同时需安装pip install keras-resnet0.1.0包。注意keras-resnet0.2.0需要安装keras2.4.3,其对应的是tensorflow2.2,因此,如果使用keras版本,应安装keras-resnet==0.1.0。