赞
踩
ps: ros系统python2.7与 python3.7安装 OpenCV有冲突所以使用anaconda创建虚拟环境,在虚拟环境中使用opencv-3.4.6
1. ubuntu 把pip也换成国内源
- mkdir ~/.pip
-
- cd ~/.pip
-
- touch pip.conf
-
- sudo nano ~/.pip/pip.conf
-
打开pip.conf 文件后,添加以下内容:
- [global]
-
- index-url = http://mirrors.aliyun.com/pypi/simple/
-
-
-
- [install]
-
- trusted-host = pypi.tuna.tsinghua.edu.cn
更新pip
python -m pip install --upgrade pip -i https://pypi.douban.com/simple
2.在windows环境下修改pip镜像源的方法(以python3.5为例)
(1):在windows文件管理器中,输入 %APPDATA%
(2):会定位到一个新的目录下,在该目录下新建pip文件夹,然后到pip文件夹里面去新建个pip.ini文件
(3):在新建的pip.ini文件中输入以下内容,搞定文件路径:"C:\Users\Administrator\AppData\Roaming\pip\pip.ini"
- [global]
- timeout = 6000
- index-url = http://pypi.douban.com/simple
- trusted-host = pypi.douban.com
更新一下:
sudo apt-get update
2.下载 与安装anaconda
自己百度!
显示现在的镜像:
conda config --show
删除清华镜像
- conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
添加中科大的:
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
-
- conda config --set show_channel_urls yes
添加清华的:
- Conda Forge
- conda config --add channels
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
-
- Conda Forge
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
-
- msys2
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
-
- bioconda
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
-
- menpo
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
-
- pytorch
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
-
- conda config --set show_channel_urls yes
删除所有源
conda config --remove-key channels
安装 第三方包报错:
Collecting package metadata (current_repodata.json): done
Solving environment: done
conda clean --all
$ conda update anaconda-navigator
Solving environment: failed
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
原因可能是防火墙的问题
解决方法:在anaconda prompt中:
conda config --set ssl_verify false
遇到以下问题
1. 关闭控制台重新启动cmd 切换环境安装 conda install numpy
Requirement already satisfied: numpy in c:\users\95444\appdata\roaming\python\python37\site-packages
2. 加上路径运行
pip install --target=c:\users\95444\appdata\roaming\python\python37\site-packages numpy
3.使用anaconda创建虚拟环境 2和3版本都可以,但是安装opencv时要注意版本号;
- # 1.
- export PATH=~/anaconda3/bin:$PATH
-
- # 2. 创建虚拟环境
- conda create -n opencvenv python=3.7
-
- # 3. 激活新创建的环境
- source activate
- source deactivate
-
- conda-env list #查看虚拟环境
- conda activate opencvenv #切换环境
- # 4. 安装opencv-python
- conda install opencv==3.4.2
- # 安装机器学习框架
- conda install scikit-learn
-
- # 5. 这时我们还需要安装扩展包
- pip install opencv-contrib-python==3.4.2.17
- 上面报错就用下面这行 后面的版本跟上; 不跟版本默认最新的,最新的没试过可能存在问题
- pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python==3.4.2.17
- #百度源 https://mirror.baidu.com/pypi/simple
- # 6.
- sudo apt-get install libcanberra-gtk-module
-
- # 7. 可能会出现下面问题:
- QObject::moveToThread: Current thread (0x55fd81f67a60) is not the object's thread (0x55fd820ef150). Cannot move to target thread (0x55fd81f67a60)
- 执行: conda install pyqt 可以就绝上述问题
- pycharm中如果编写代码没有提示,可以考虑将工程下面的.idea文件删除,再重新打开pycharm
- # 采用这种方式安装,在当前版本中会出现如下异常
- The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
-
-
-
-
如果 报conda 不存在:
1.控制台执行这个 export PATH=~/anaconda3/bin:$PATH
2.
也可以在pychram 中的控制台中执行,但前提是要配编译环境,编译环境配置在最下面
运行 cv.imshow("src",imwrite) 显示以下黑框原因是你安装了 4.3 版本的openCV,安装时一定要跟上版本号;
以下安装notebook看自己需求,需要就安装notebook
安装jupyter notebook
conda install jupyter notebook
安装jupyter notebook的代码提示功能
1.
- 我的是在anaconda中的root环境下运行以下命令,在其他环境下发现没有效果
-
- 1
-
- pip install jupyter_contrib_nbextensions
-
- jupyter contrib nbextension install --user
-
-
-
- 2.
-
- pip install --user jupyter_nbextensions_configurator
-
- jupyter nbextensions_configurator enable --user
-
-
-
- 3.安装成功会在http://localhost:8888/tree中出现Nbextensions
2.
- pip install jupyter_contrib_nbextensions
- conda install jupyter_contrib_nbextensions
- //上一行报错就用这行代替
- pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter_contrib_nbextensions
-
- jupyter contrib nbextension install --user --skip-running-check
- 或
- conda install -c conda-forge jupyter_nbextensions_configurator
启动jupyter notebook
jupyter notebook
点开 Nbextensions 的选项,并勾选 Hinterland
1. Jupyter Notebook有两种mode
2. Command命令快捷键:
3. Edit命令快捷键:
Jupyter Notebook里command模式快捷键H,查看所有快捷键
快捷键: 原文链接:https://www.cnblogs.com/peilin1031/p/12326701.html
更新pip
python -m pip install --upgrade pip -i https://pypi.douban.com/simple
查看环境
conda-env list
新建环境
conda create -n tfenv python=3.7
激活环境
conda activate tfenv
切换到自己需要的环境中 conda activate tfenv 执行以下自己需要使用的库:
安装库scikit-learn
jupyter notebook 中安装
!pip install -U scikit-learn
scikit-learn安装
pip install scikit-learn -i https://mirror.baidu.com/pypi/simple
安装库opencv
jupyter notebook 中安装
!pip install opencv-python
- !pip install --upgrade pip
- %time !pip install msgpack
opencv安装
pip install opencv-python==3.4.2.16 -i https://mirror.baidu.com/pypi/simple
matplotlib
pip install matplotlib -i https://mirror.baidu.com/pypi/simple
谷歌官方推出的深度学习框架, 目前最新版是2.3的版本, 2.x版本简洁,易用.
conda create -n tfenv python=3.7
conda activate tfenv
conda install pip
pip install tensorflow -i https://mirror.baidu.com/pypi/simple
jupyter notebook 中不能使用 TensorFlow 请切换到 conda activate tfenv 环境后运行以下两条命令
pip install ipython -i https://mirror.baidu.com/pypi/simple
pip install jupyter -i https://mirror.baidu.com/pypi/simple
解析返回的html与json数据,用爬虫获取数据时会用到
- #解析返回的html与json数据
- !pip install Beautifulsoup4
scikit-learn
pip install scikit-learn -i https://mirror.baidu.com/pypi/simple
安装python开发web程序的依赖
conda install flask
socketio eventlet socket通讯需要的依赖
conda install -c conda-forge python-socketio
conda install -c conda-forge eventlet
- pip install python-socketio -i https://mirror.baidu.com/pypi/simple
- pip install eventlet -i https://mirror.baidu.com/pypi/simple
第三方图片数据增强
pip install imgaug
pip install pandas
pip install matplotlib
pip install numpy
可视化工具graphviz安装
- # graphviz
- # windows 双击安装提供的软件,然后把安装路径的bin目录添加到环境变量
- # C:\Program Files (x86)\Graphviz2.38\bin
- # linux : sudo apt-get install graphviz
- !pip install pydot
在jupyter notebook中使用
tf.keras.utils.plot_model(model,to_file='model.png',show_shapes=True,show_layer_names=True)
效果
开启GPU运算报错:
Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
对GPU进行按需分配,避免GPU内存不够
- from tensorflow.compat.v1 import ConfigProto
- from tensorflow.compat.v1 import InteractiveSession
-
- config = ConfigProto()
- config.gpu_options.allow_growth = True
- session = InteractiveSession(config=config)
-
----------------------------------------------------------------------------------------------------------------
jupyer book 切换conda环境
使用Jupyter Notebook时就需要制定使用的虚拟环境,使用时需要进入安装nb_conda的虚拟环境中使用
conda install nb_conda
要关联的环境安装 切换环境 有效
conda install nb_conda_kernels
更新libsodium的版本
conda install -c conda-forge libsodium
#下面这个好像没用
当安装了新的conda虚拟环境时,发现在Jupyter Notebook中无法使用,可以在你的新环境上安装ipykernel,重启jupyter之后就可以用了
conda install -n python_env ipykernel
安装ipykernel时先切换环境
- conda-env list #查看虚拟环境
- conda activate opencvenv #切换环境
conda install ipykernel
sudo apt-get install python-pip python-dev
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.14.0-cp27-none-linux_x86_64.whl
sudo pip2 install --ignore-installed --upgrade $TF_BINARY_URL
安装碰到的问题
问题1:Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决方法
python2.7 -m pip install tensorflow --ignore-installed six
问题2:launchpadlib 1.10.2 requires testresources, which is not installed.
解决方案:
sudo pip install launchpadlib
用ros启动pychon时禁用conda ,把里面的conda路径注释掉
~/.bashrc
- cat ~/.bashrc
- vim ~/.bashrc
- source ~/.bashrc
-------------------------------------------------------------------
在pip install 库文件 时出现该错误:直接上干货,亲测有效!
1.在C:\Windows\System32该目录下,找到下面两个文件
2.到Anaconda的根目录下,进入\anaconda\install\Lib\site-packages\win32该目录,并将上面两个文件拷贝进行替换
3.此时再次进行安装操作,bug完美解决
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。