最近把自己在windows上的Django项目放在的Ubuntu上,启动时提示找不到模块

原来是自己的项目用的是虚拟环境,安装的第三方库全部在虚拟环境中 AutoTestSite/venv/Lib/site-packages

在Ubuntu中查看模块搜索路径:

chen@ubuntu:~$ python
Python 2.7. (default, Nov , ::)
[GCC 5.4. ] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/chen', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

发现并没有这个路径:AutoTestSite/venv/Lib/site-packages

所以需要添加路径:

编辑文件 sudo vi .bashrc ,在最下方添加:

export PYTHONPATH="/home/**/**/venv/Lib/site-packages:$PYTHONPATH"
chen@ubuntu:~$ sudo vi .bashrc 

# ~/.bashrc: executed by bash() for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples # If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac # don't put duplicate lines or lines starting with space in the history.
# See bash() for more options
HISTCONTROL=ignoreboth # append to the history file, don't overwrite it
shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash()
HISTSIZE=
HISTFILESIZE= # check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar # add python project autotestsite module search path assress
export PYTHONPATH="/home/guchen/python/www/for_test/AutoTestSite/venv/Lib/site-packages:$PYTHONPATH"

执行:source .bashrc

使修改生效

再次查看sys.path,已经添加了

chen@ubuntu:~$ python
Python 2.7. (default, Nov , ::)
[GCC 5.4. ] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/chen/python/www/AutoTestSite/venv/Lib/site-packages', '/home/chen', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

Ubuntu下添加Python环境变量的更多相关文章

  1. Mac下添加java环境变量

    2015年4月22号更新: 发现一个坑:最近发现有同事按照本文方式配置jdk环境变量一直不成功,后来发现他是使用了“Oh-My-Zsh”,配置文件的路径不是/etc/profile或~/.bash_p ...

  2. Ubuntu 下生成 python 环境安装文件 requirements.txt

    参考: 查找python项目依赖并生成requirements.txt Ubuntu 下生成 python 环境安装文件 requirements.txt 首先通过 pip 安装pyreqs模块: p ...

  3. Ubuntu 下开发 Android 环境变量设置

    -----------------------------------------------------ANDROID_SDK_HOME:/home/cmm/avds PATH:/home/cmm/ ...

  4. linux下添加PATH环境变量

    添加PATH环境变量,第1种方法:[root@lx_web_s1 ~]# export PATH=/usr/local/webserver/mysql/bin:$PATH 再次查看: [root@lx ...

  5. ubuntu 应用添加进环境变量

    BG:公司同事使用的电脑系统大多为windows ,有部分mac和Ubuntu(我就是那个部分Ubuntu),某些情况为了统一格式,便下载了一些解压即可使用的软件,但是每次点开文件夹然后点开程序很繁琐 ...

  6. kali下添加PATH环境变量

    添加PATH环境变量,第1种方法: [root@lx_web_s1 ~]# export PATH=/usr/local/webserver/mysql/bin:$PATH 再次查看: [root@l ...

  7. ubuntu下配置java环境变量

    1.官网下载linux对应的jdk安装包tar.gz 2.filezilla上传tar.gz到对应ubuntu目录test下(见上一篇) 3.解压:tar -zcvf XXX.tar.gz 4.修改解 ...

  8. ubuntu下配置JDK7环境变量

    ubuntu下JDK配置本质上和win是一样的: 1.去官网下载JDK7,找jdk-7u21-linux-i586.tar.gz并下载:http://www.oracle.com/technetwor ...

  9. win10下配置python环境变量(Python配置环境变量)

    从官网下载Windows下的python版本,一路按照默认进行安装. 安装之后配置环境变量的步骤如下: 1,点“我的电脑”,右键选“属性”. 2,选择“高级系统设置”--->选“环境变量”--- ...

随机推荐

  1. CAN总线优点

    废除传统的站地址编码,代之以对通信数据块进行编码,可以多主方式工作: 采用非破坏性仲裁技术,当两个节点同时向网络上传送数据时,优先级低的节点主动停止数据发送,而优先级高的节点可不受影响继续传输数据,有 ...

  2. Java 数组的三种创建方法,数组拷贝方法

    public static void main(String[] args) {//创建数组的第一种方法int[] arr=new int[6];int intValue=arr[5];//Syste ...

  3. oracle显示数据库名和表名

    oracle查看表名 select table_name from user_tables; select table_name from dba_tables; select * from all_ ...

  4. babel-preset-latest使用介绍

    本文介绍babel中的babel-preset-latest插件 简介 该插件的作用是包含了每年的js代码转换规则 默认包含es2015,es2016,es2017,默认对这些代码都会进行转码,从而方 ...

  5. RAD 10 新控件 TSearchBox TSplitView

    Seattle新控件 1.TSearchBox Events OnInvokeSearch published Occurs when the search indicator button is c ...

  6. 监控和安全运维 1.8 zabbix服务端安装

    1. Zabbix简介基于web的开源软件,开源监控系统状态也可以监控网络设备.和nagios不同的是zabbix会把获取的数据保存在数据库中,所以zabbix需要有数据库支持 Zabbix还可以自动 ...

  7. struct 方法使用

    struct _Worker { _Worker() { pWokerbase=NULL; hThread=INVALID_HANDLE_VALUE; pListConn=NULL; } struct ...

  8. Hadoop IO基于文件的数据结构详解【列式和行式数据结构的存储策略】

    Charles所有关于hadoop的文章参考自hadoop权威指南第四版预览版 大家可以去safari免费阅读其英文预览版.本人也上传了PDF版本在我的资源中可以免费下载,不需要C币,点击这里下载. ...

  9. wpa_supplicant移植与使用(转)

    下载wpa_supplicant最新版和openssl(编译wpa_supplicant需要openssl的库) 我这里使用的是wpa_supplicant-0.7.3.tar.gz和openssl- ...

  10. 非常详细的ok6410的linux系统移植…

    目录 Linux 3.3.5系统移植 2 LED驱动移植 8 按键驱动移植 9 LCD驱动移植 11 DM9000网卡驱动移植 14 搭建NFS网络文件系统 25 移植触摸屏驱动 38 移植Qt4.8 ...