zoukankan      html  css  js  c++  java
  • (坑集)Python环境配置

    如题记录一些python环境配置中出现的坑:


    一、ubuntu下使用pip安装mysqlclient包

        如果出现在ubuntu下安装mysqlclient包失败的情况下,可以先在使用apt-get安装libmysqlclient-dev,即:

    sudo apt-get install libmysqlclient-dev

        然后再正常使用pip安装mysqlclient即可。


    二、centos下使用pip安装mysqlclient包

        如果出现了下面这种问题,说明你正在使用python3,并且缺少静态文件

     #include "Python.h"
                            ^
        编译中断。
        error: command 'gcc' failed with exit status 1

        输入yum search devel|grep python,获取符合你python3版本的devel,安装后,mysqlclient安装成功。


    三、virtualenvwrapper配置报错

        在安装好virtualenvwrapper之后,需要在~/.bashrc中配置,把vw的.sh文件添加进去,还可以选择修改虚拟环境默认保存的位置。

        首先在编辑.bashrc之前,你需要知道virtualenvwrapper.sh文件的路径,使用下面的命令查找

    sudo find / -name virtualenvwrapper.sh

       下面是我的查找结果

        因为我是直接安装在我的用户路径下的,所以如果你是安装在根目录下,结果应该是/usr/local/bin/virtualenvwrapper.sh

        得知路径之后就可以在~/.bashrc文件中添加下面配置

    export WORKON_HOME=$HOME/virtualenvs # 配置虚拟环境的保存位置 $HOME是用户的主目录
    source /home/God/.local/bin/virtualenvwrapper.sh # 配置virtualenvwrapper命令的脚本 

        第一条配置可以随你的喜爱去更改,但是第二条配置需要使用刚才获取路径,只有命令脚本路径正确才可在linux中直接使用virtualenvwrapper中的命令。

        修改.bashrc文件后,需要重新加载.bashrc文件

    source ~/.bashrc
    

    重点!!!

        如果你的环境是python3,重新加载后,可能会出现这样类似的错误

    /usr/bin/python: No module named virtualenvwrapper
    virtualenvwrapper.sh: There was a problem running the initialization hooks. 
    If Python could not import the module virtualenvwrapper.hook_loader,
    check that virtualenvwrapper has been installed for
    VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
    set properly.

        因为在virtualenvwrapper.sh中有如下代码

    # Locate the global Python where virtualenvwrapper is installed.
    if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then
        VIRTUALENVWRAPPER_PYTHON="$(command which python)"
    fi

       脚本会默认使用python2环境,但是virtualenvwrapper装在了python3环境中,所以会有上面的报错。

       解决办法:

       直接将VIRTUALENVWRAPPER_PYTHON默认值修改为/usr/bin/python3即可

    # Locate the global Python where virtualenvwrapper is installed.
    VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
    if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then
        VIRTUALENVWRAPPER_PYTHON="$(command which python)"
    fi

        修改后,按照上面步骤,重新加载下virtualenvwrapper.sh即可解决问题。


  • 相关阅读:
    (HDU)1393 -- Weird Clock (奇怪的时钟)
    (HDU)1391 -- Number Steps (数字阶梯)
    (HDU)1390 -- Binary Numbers(二进制数)
    (HDU)1339 -- A Simple Task(简单任务)
    (HDU)1335 -- Basically Speaking(基础和交流)
    论文笔记:Fully-Convolutional Siamese Networks for Object Tracking
    论文笔记:Visual Object Tracking based on Adaptive Siamese and Motion Estimation Network
    论文笔记:Attentional Correlation Filter Network for Adaptive Visual Tracking
    论文笔记:Deep Attentive Tracking via Reciprocative Learning
    Learning Spatial-Temporal Regularized Correlation Filters for Visual Tracking---随笔
  • 原文地址:https://www.cnblogs.com/GF66/p/9785479.html
Copyright © 2011-2022 走看看