在这篇文章中,我们将为您详细介绍OError:[Errno26]文本文件忙:“/…myvirtualenv/bin/python”的内容,并且讨论关于文本文件file操作的相关问题。此外,我们还会涉及
在这篇文章中,我们将为您详细介绍OError:[Errno 26]文本文件忙:“ /…myvirtualenv / bin / python”的内容,并且讨论关于文本文件file操作的相关问题。此外,我们还会涉及一些关于ERROR: virtualenvwrapper could not find virtualenv in your path、IndentationError:创建python3 virtualenv时意外缩进、IOError:[Errno 32]管道损坏:Python、Linux服务器超简单安装Python3环境、Ipython、Jupyter、virtualenv、virtualenvwrapper教程全在这了的知识,以帮助您更全面地了解这个主题。
本文目录一览:- OError:[Errno 26]文本文件忙:“ /…myvirtualenv / bin / python”(文本文件file操作)
- ERROR: virtualenvwrapper could not find virtualenv in your path
- IndentationError:创建python3 virtualenv时意外缩进
- IOError:[Errno 32]管道损坏:Python
- Linux服务器超简单安装Python3环境、Ipython、Jupyter、virtualenv、virtualenvwrapper教程全在这了
OError:[Errno 26]文本文件忙:“ /…myvirtualenv / bin / python”(文本文件file操作)
我尝试重新创建virtualenv:
foo_bar_d@aptguettler:~$ virtualenv --system-site-packages .
我得到这个异常:
foo_bar_d@aptguettler:~$ virtualenv --system-site-packages .New python executable in /home/foo_bar_d/bin/pythonTraceback (most recent call last): File "/usr/local/bin/virtualenv", line 11, in <module> sys.exit(main()) File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 711, in main symlink=options.symlink) File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 924, in create_environment site_packages=site_packages, clear=clear, symlink=symlink)) File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1230, in install_python shutil.copyfile(executable, py_executable) File "/usr/lib/python2.7/shutil.py", line 83, in copyfile with open(dst, ''wb'') as fdst:IOError: [Errno 26] Text file busy: ''/home/foo_bar_d/bin/python''
有人知道为什么会发生这种异常吗?
答案1
小编典典我有同样的问题 :)
virtualenv通过修改virtualenv目录区域中python可执行文件的副本来工作(afaik)。
您必须已经有一个使用virtualenv的进程,以便python可执行文件的副本“在使用中”(从技术上讲,它是在执行时将mmap()放入内存)。
除非您需要更改virtualenv的设置,否则不需要每次都重新运行virtualenv命令-设置完成后,只需在需要时将其激活即可。
关于发生这种情况的原因-引导时可能正在运行服务:
ps -ef | grep python
ERROR: virtualenvwrapper could not find virtualenv in your path
环境:
- Ubuntu 18.04
- python3
使用pip3安装virtualenv
和virtualenvwrapper
两个包,ubuntu18.04中,用户使用pip安装的包在~/.local/
下,在.bashrc
中添加的配置如下:
# Python Virtualenv Settings export WORKON_HOME=~/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source ~/.local/bin/virtualenvwrapper.sh
使用mkvirtualenv
创建虚拟环境时,报错如下:
[email protected]:~$ mkvirtualenv remote ERROR: virtualenvwrapper Could not find virtualenv in your path
提示virtualenv 不在环境中,需要在配置文件添加virtualenv的路径进去,具体配置如下:
# Python Virtualenv Settings export WORKON_HOME=~/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # 指定virtualenv的路径 export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv source ~/.local/bin/virtualenvwrapper.sh
然后重新加载.bashrc
文件即可
IndentationError:创建python3 virtualenv时意外缩进
如何解决IndentationError:创建python3 virtualenv时意外缩进?
以前,我的virtualenv
命令对python3完全可用。但是现在当我尝试创建虚拟环境时:
$ virtualenv -p python3 .
它给我以下错误:
Running virtualenv with interpreter /home/user/anaconda3/bin/python3
Already using interpreter /home/user/anaconda3/bin/python3
Using base prefix ''/home/user/anaconda3''
New python executable in /home/user/Documents/cynical/sitemap/bin/python3
Not overwriting existing python script /home/user/Documents/cynical/sitemap/bin/python (you must use /home/user/Documents/cynical/sitemap/bin/python3)
Command /home/user/Documents.../sitemap/bin/python3 -m pip config list had error code 1
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py",line 2635,in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py",line 870,in main
symlink=options.symlink,File "/usr/local/lib/python2.7/dist-packages/virtualenv.py",line 1173,in create_environment
install_wheel(to_install,py_executable,search_dirs,download=download)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py",line 1019,in install_wheel
_install_wheel_with_search_dir(download,project_names,search_dirs)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py",line 1046,in _install_wheel_with_search_dir
config = _pip_config(py_executable,python_path)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py",line 1128,in _pip_config
config[key] = ast.literal_eval(value)
File "/home/user/anaconda3/lib/python3.7/ast.py",line 46,in literal_eval
node_or_string = parse(node_or_string,mode=''eval'')
File "/home/user/anaconda3/lib/python3.7/ast.py",line 35,in parse
return compile(source,filename,mode,PyCF_ONLY_AST)
File "<unkNown>",line 1
_get_module_details(mod_name,_Error)
^
IndentationError: unexpected indent
我也尝试过更新pip3,python3和virtualenv。
$ apt install python3
$ apt install python3-pip
$ apt install virtualenv
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
IOError:[Errno 32]管道损坏:Python
我有一个非常简单的Python 3脚本:
f1 = open(''a.txt'', ''r'')print(f1.readlines())f2 = open(''b.txt'', ''r'')print(f2.readlines())f3 = open(''c.txt'', ''r'')print(f3.readlines())f4 = open(''d.txt'', ''r'')print(f4.readlines())f1.close()f2.close()f3.close()f4.close()
但它总是说:
IOError: [Errno 32] Broken pipe
我在网上看到了解决此问题的所有复杂方法,但是我直接复制了此代码,因此我认为代码有问题,而不是Python的SIGPIPE。
我正在重定向输出,因此,如果上面的脚本被命名为“ open.py”,那么我要运行的命令将是:
open.py | othercommand
答案1
小编典典我没有重现这个问题,但是也许这种方法可以解决这个问题:(逐行写入stdout
而不是使用print
)
import syswith open(''a.txt'', ''r'') as f1: for line in f1: sys.stdout.write(line)
你能抓住破损的管道吗?这将文件stdout
逐行写入,直到关闭管道为止。
import sys, errnotry: with open(''a.txt'', ''r'') as f1: for line in f1: sys.stdout.write(line)except IOError as e: if e.errno == errno.EPIPE: # Handle error
您还需要确保othercommand
在管道变得太大之前正在从管道读取-https:
//unix.stackexchange.com/questions/11946/how-big-is-the-pipe-
buffer
Linux服务器超简单安装Python3环境、Ipython、Jupyter、virtualenv、virtualenvwrapper教程全在这了
一、网卡配置
vim /etc/sysconfig/network-scripts/ifcfg-ens33
ONBOOT=''yes''
二、更换Linux语言环境
1.修改配置文件
vim /etc/locale.conf
LANG="zh_CN.UTF-8"
2.更改后查看系统语言变量
locale
三、更换yum repo源
cd /etc/yum.repos.d
1.好习惯,备份yum源
mkdir repo_bak
mv *.repo repo_bak/
2.下载阿里云repo文件
wget http://mirrors.aliyun.com/repo/Centos-7.repo
3.清空yum缓存并且生成新的yum缓存
yum clean all
yum makecache
4.安装软件扩展源
yum install -y epel-release
四、python3安装
1.下载python3.6.7
1.1 切换到opt目录
cd /opt
1.2 下载python3.6.7
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
1.3 解压下载后的python压缩包
tar -zxvf Python-3.6.7.tgz
2.下载python3依赖文件
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel
openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
3.编译Python3
3.1 进入解压后的python包
cd Python-3.6.7
3.2 安装python3
./configure --prefix=/opt/python36/
3.3 编译Python3
make install
3.4 创建python3快捷方式
方式一: 软连接(这一步很麻烦,并且不适用于virtualenv的创建)
ln -s /opt/python36/bin/python3.6 /usr/bin/python3 #但是这一步还没有pip
ln -s /opt/python36/bin/pip3 /usr/bin/pip3
方式二: 配置环境变量,永久生效,写入到文件/etc/profile中,每次登录就生效
vim /etc/profile #将此配置写到最低行
PATH=/opt/python36/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile #读取这个文件,让环境变量重新生效
4、升级pip3
pip3 install --upgrade pip
五、安装ipython解释器
1.安装ipython,指定douban源下载
pip3 install -i https://pypi.douban.com/simple ipython
六、安装并调试Jupyter
1、安装Jupyter
pip3 install -i https://pypi.douban.com/simple jupyter
2、调试jupyter
2.1进入ipython环境,给jupyter设置密码
ipython from IPython.lib import passwd
passwd()
Enter password:
Verify password:
Out[2]: ''sha1:64ad62e6d8a1:8d80ed008ea27d9523cddc40fb12d75082316d43''
2.2 编译朱皮特的配置文件
jupyter notebook --generate-config --allow-root
2.3编译朱皮特的配置文件
vim ~/.jupyter/jupyter_notebook_config.py
2.4修改如下配置一致即可
c.NotebookApp.ip = ''可以写ip或者0.0.0.0''
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8000
2.5启动朱皮特
jupyter notebook --allow-root #启动notebook
2.6如果启动不了,很可能是防火墙问题
2.6.1
iptables -L 查看防火墙规则
iptables -F 清空防火墙规则
2.6.2
systemctl stop firewalld #关闭防火墙服务
systemctl disable firewalld #从开机自启中,移除这个防火墙服务,永久关闭
2.6.3
关闭selinux
1.查看selinux规则 getenforce
2.临时关闭selinux setenforce 0
注意:
永久关闭selinux,需重启生效
vim /etc/selinux/config
写入以下配置
SELINUX=disabled
重启服务器生效
七、安装虚拟环境
1.虚拟环境安装
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv
2.通过virtualenv命令,创建虚拟环境
2.1 切换到要创建虚拟环境的目录
virtualenv --no-site-packages --python=python3 venv1
2.2参数解释
--no-site-packages 创建一个干净,隔离宿主机环境的虚拟环境
--python=python3 指定解释器为python3解释器
3.虚拟环境的进入与退出
进入虚拟环境
读取已创建虚拟环境中的bin目录下的activate文件
e.g: source /opt/all_env/venv1/bin/activate
退出虚拟环境
deactivate
4.检查环境变量PATH,检查是否正确激活了虚拟环境
echo $PATH
5.检查虚拟环境下的python3和pip3目录位置
which python3
which pip3
6.使用虚拟环境进行项目开发
6.1 例如使用虚拟环境env1开发django1.11.11版本的项目
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple django==1.11.11
6.2 例如使用虚拟环境env2开发django2.0版本的项目
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple django==2.0
八、虚拟环境管理工具virtualenvwrapper
1.下载virtualenvwrapper
pip3 install -i https://pypi.douban.com/simple virtualenvwrapper
2.配置全局变量,设置virtualenvwrapper.sh脚本文件自启动
2.1 打开登陆用户家目录下的.bashrc文件
vim ~/.bashrc
2.2 填写参数
#设置virtualenv的统一管理目录
export WORKON_HOME=~/Envs
#添加virtualenvwrapper的参数,生成干净隔绝的环境
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS=''--no-site-packages''
#指定python解释器
export VIRTUALENVWRAPPER_PYTHON=/opt/python36/bin/python3
#执行virtualenvwrapper安装脚本
source /opt/python36/bin/virtualenvwrapper.sh
:wq保存退出
2.3 重新加载.bashrc文件
source ~/.bashrc
3.virtualenvwrapper使用方法
3.1.创建虚拟环境,创建后虚拟环境位置在WORKON_HOME目录下
mkvirtualenv env1
3.2.查看当前机器所有的虚拟环境
lsvirtualenv
3.3.激活某个虚拟环境或切换为某个虚拟环境
workon env1
3.4.删除某个虚拟环境
rmvirtualenv env1
3.5.切换到当前虚拟环境的目录(前提是当前环境为虚拟环境)
cdvirtualenv env1
九、确保项目的环境一致性
1.导出当前python环境的包
pip3 freeze > requirements.py
2.将requirements.py上传至服务器后,在服务器下创建一个虚拟环境,在虚拟环境中导入项目所需的模块依赖
pip3 install -r requirements.py
关于OError:[Errno 26]文本文件忙:“ /…myvirtualenv / bin / python”和文本文件file操作的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于ERROR: virtualenvwrapper could not find virtualenv in your path、IndentationError:创建python3 virtualenv时意外缩进、IOError:[Errno 32]管道损坏:Python、Linux服务器超简单安装Python3环境、Ipython、Jupyter、virtualenv、virtualenvwrapper教程全在这了的相关知识,请在本站寻找。
本文标签: