zoukankan      html  css  js  c++  java
  • python环境问题

    一.电脑内的环境

    1.查看:where python

    2.查看里面的库:pip list

    3.查看当前python环境:import sys>>print(sys.path)

    4.python的标准库位置:%python安装路径%Lib

    5.python的第三方库位置:%python安装路径%Libsite-packages

    6.查看tensorflow版本。print(tf.__version__)

    7.查看anconda版本:conda -V

    8.查看tensorflow用的cpu还是gpu:

    import os

    from tensorflow.python.client import device_lib

    os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"

    if __name__ == "__main__":

       print(device_lib.list_local_devices())

    import tensorflow as tf
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

    9.查看GPU运行情况:将nvidia-smi.exe拉入cmd界面,回车

     10.cuda安装成功:nvcc -V

     11.安装完anaconda后要激活python,在prompt里面输入conda activate D:SoftwareAnaconda,删除C:Usersdengzhuo.condarc

    二.虚拟环境

    1.查看:conda info --envs

    2.创建:conad create -n (name) python=3.6

    3.激活:activate (name)

    4.删除:conda remove --name name  --all

    5.退出:conda deactivate 

    6.导出环境需要的包:pip freeze > requirements.txt(此时会生成一个requirements文件)

    7.下载环境需要的包:pip install -r requirements.txt

    5.选择gpu:

    import os
    os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 
    os.environ[”zCUDA_VISIBLE_DEVICES”] = "0"os.environ[“CUDA_VISIBLE_DEVICES”] = “0,1”
    6.创建环境的命令输入后,有两个done,但还是找不到这个环境,而且没创建:
    原因:要清楚anaconda缓存:

    方法:conda clean -p # 删除没有用的包 --packages
    conda clean -t # 删除tar打包 --tarballs
    conda clean -y -all # 删除所有的安装包及cache(索引缓存、锁定文件、未使用过的包和tar包)



    三.修改jupyter的工作目录:

    1.开始栏找到upyter Notebook 快捷方式
    2.右键->更多->查看文件位置 找到Jupyter文件的位置
    3.右键->属性 将目标栏最后面的%USERPROFILE%,修改为D: otebook_dir此处写你想用的工作目录,然后点保存
    4.重启Jupyter Notebook,可以看到目录已改。
    四。源

    conda 国内源:

    # 查看当前源
    conda config --show-sources
    # 添加源
    #conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ #清华源停服
    # 腾讯云
    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/free/
    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/main/
    conda config --set show_channel_urls yes
    # 换回默认源
    conda config --remove-key channels

    pip 国内源
    阿里云 :http://mirrors.aliyun.com/pypi/simple/
    中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
    豆瓣(douban) :http://pypi.douban.com/simple/
    清华大学 :https://pypi.tuna.tsinghua.edu.cn/simple/
    中国科学技术大学: http://pypi.mirrors.ustc.edu.cn/simple/

    # 使用豆瓣源安装
    pip install opencv-python -i http://pypi.douban.com/simple
    # 报错说不信任该源,执行如下:
    pip install opencv-python -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

    使用pip更新所有包:

    $ pip install pip-review

    $ pip-review --local --interactive
    jupyter notebook连不上kernel:在prompt中:conda clean -tipsy>>>
    >>>>pip uninstall ipykernel>>>pip uninstall ipython>>>pip uninstall jupyter_client>>
    >pip uninstall jupyter_core>>>pip uninstall traitlets>>>pip uninstall ipython-genutils>>>再重新安装

  • 相关阅读:
    [redis读书笔记] 第二部分 sentinel
    [redis读书笔记] 第三部分 多机数据库的实现 复制
    单线程的REDIS为什么这么快?
    [redis读书笔记] 第二部分 单机数据库 RDB持久化
    [redis读书笔记] 第二部分 单机数据库 数据库实现
    选靓号——拼多多笔试题(贪心+暴力)
    种树——拼多多笔试题(暴搜+剪枝)
    【学习笔记】《Java编程思想》 第8~11章
    leetcode——二分
    CodeForces-1265E(期望)
  • 原文地址:https://www.cnblogs.com/Turing-dz/p/12794015.html
Copyright © 2011-2022 走看看