我正在尝试将一个开源库移植到Python 3.(SymPy,如果有人想知道的话.)
所以,我需要2to3在为Python 3构建时自动运行.为此,我需要使用distribute.因此,我需要移植当前系统(根据doctest)distutils.
不幸的是,我不知道什么是这些模块-之间的区别distutils,distribute,setuptools.文档是最好的粗略,因为它们似乎都是彼此的分支,旨在在大多数情况下兼容(但实际上,不是全部)......等等.
有人可以解释这些差异吗?我应该用什么?什么是最现代的解决方案?(Distribute顺便说一句,我也很欣赏一些关于移植的指南,但这有点超出了问题的范围......)
我最近学会了如何在我的工作流程中使用virtualenv和virtualenvwrapper,但我在一些指南中看到了pyenv,但我似乎无法理解pyenv是什么以及它与virtualenv的不同/相似之处.pyenv是virtualenv或免费工具的更好/更新的替代品吗?如果后者有什么不同的做法,那么两者(以及virtualenvwrapper,如果适用)如何协同工作?
我怎样才能使用PYTHONPATH?当我尝试在路径中运行脚本时,找不到该文件.当我cd到包含脚本的目录时,脚本运行.那么PYTHONPATH有什么用呢?
$ echo $PYTHONPATH
:/home/randy/lib/python
$ tree -L 1 '/home/randy/lib/python'
/home/randy/lib/python
??? gbmx_html.py
??? gbmx.py
??? __init__.py
??? __pycache__
??? scripts
??? yesno.py
$ python gbmx.py -h
python: can't open file 'gbmx.py': [Errno 2] No such file or directory
$ cd '/home/randy/lib/python'
Run Code Online (Sandbox Code Playgroud)
cd到文件目录后运行..
$ python gbmx.py -h
usage: gbmx.py [-h] [-b]
Run Code Online (Sandbox Code Playgroud)
为什么我不能使用PYTHONPATH?
我正在尝试使用运行Debian的Raspberry Pi上的Python 2.6访问串口.我的脚本命名serial.py尝试导入pySerial:
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600)
ser.write("hello world!")
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它拒绝与此错误建立串行连接:
AttributeError: 'module' object has no attribute 'Serial'
Run Code Online (Sandbox Code Playgroud)
当我尝试在交互式Python解释器中键入相同的代码时,它仍然无法正常工作.
奇怪的是,它曾经在几个小时前工作.
可能是什么问题呢?我试图修复一段时间,再次安装pySerial,重写我的代码,仔细检查串口等.
提前致谢!
我编辑什么文件,以及如何编辑?我创建了一个虚拟环境.
脚本:
我在python中编写了一个脚本,偶尔会向Twitter发送推文
它只使用一个名为:tweepy
的库,安装它工作的库后,很棒.
问题:
我想在没有安装任何权限的服务器上托管脚本
如果我可以从我所拥有的文件夹中本地包含它,那将会很棒.
截至目前,我只需要包含在我的文件的顶部是:
import tweepy
Run Code Online (Sandbox Code Playgroud)
在tweepy文件夹(也有一个__init__.py我认为是非常重要的文件.
问题:
如何在不安装的情况下使用此库?
基本上我想替换:import tweepy用import local_folder/tweepy/*
这可能只是蟒蛇常识,但我卡住了!
我有一个从虚拟环境安装的软件包.如果我只是启动python解释器,那么该包可以很好地导入.但是,如果我启动Idle,则无法导入该包(因为它仅在一个特定的virtualenv中可用而不是全局).如何从virtualenv启动Idle,以便virtualenv的所有包都可用?
我使用python 2.7 + virtualenv版本1.10.1来运行myproject项目.由于一些其他项目的要求,我必须使用其他版本的python(Python 3.5)和Django 1.9.为此我在我的用户目录中安装了python.此外,我已经下载并将virtualenv(版本 - 15.1.0)安装到我的用户目录中.但每当我尝试创建虚拟环境时,我都会收到以下错误
python virtualenv/virtualenv.py myproject
Run Code Online (Sandbox Code Playgroud)
Using base prefix '/home/myuser/python3'
New python executable in /home/mount/myuser/project_python3/myproject/bin/python
ERROR: The executable /home/mount/myuser/project_python3/myproject/bin/python is not functioning
ERROR: It thinks sys.prefix is '/home/myuser/python3' (should be '/home/mount/myuser/project_python3/myproject')
ERROR: virtualenv is not compatible with this system or executable
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这件事我做错了什么
要向这里关于 pyenv、venv、virtualenv 和 virtualenvwrapper的好问题和讨论添加一个问题,有人可以解释一下 conda 环境如何适应这个世界吗?conda 环境与其他虚拟环境选项的首选用例是什么时候?
我在较旧的操作系统上运行Python,其系统Python版本为2.6.因此我在我的主目录中安装了2.7并使用该Python获取pip,并使用该pip来安装virtualenvwrapper.所以我有
$ which python pip virtualenv virtualenvwrapper.sh
/home/user/bin/python
/home/user/bin/pip
/home/user/.local/bin/virtualenv
/home/user/.local/bin/virtualenvwrapper.sh
Run Code Online (Sandbox Code Playgroud)
我使用这些工具创建virtualenv,并尝试安装模块
$ mkvirtualenv fred
New python executable in fred/bin/python2.7.10
Also creating executable in fred/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/preactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/postactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/get_env_details
$ workon fred
$ export PYTHONPATH=/home/user/.virtualenvs/fred/lib/python2.7/site-packages
$ /home/user/.virtualenvs/fred/bin/easy_install --prefix=/home/user/.virtualenvs/fred pip
Creating /home/user/.virtualenvs/fred/lib/python2.7/site-packages/site.py
Searching for pip
Best match: pip 7.1.2
Adding pip 7.1.2 to easy-install.pth file
Installing pip script to /home/user/.virtualenvs/fred/bin
Installing pip3.4 script to /home/user/.virtualenvs/fred/bin
Installing …Run Code Online (Sandbox Code Playgroud) python ×10
virtualenv ×6
pyenv ×2
unix ×2
conda ×1
distribute ×1
distutils ×1
django ×1
import ×1
linux ×1
module ×1
packaging ×1
pip ×1
python-2.7 ×1
python-3.x ×1
python-idle ×1
python-venv ×1
raspberry-pi ×1
serial-port ×1
setuptools ×1