TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Pip -t: A simple and transparent alternative to virtualenv in Python

74 点作者 fzumstein将近 10 年前

18 条评论

Galanwe将近 10 年前
I don&#x27;t really get what this is supposed to solve.<p>- `virtualenv` works by creating an overlay of the `site-packages` in `$VIRTUALENV`, and change the shebang of scripts to use absolute path of python in the overlay. That way, not only do you get dependencies isolation, but you can also call directly your programs from outside the virtualenv and it will work.<p>What you propose is both bad practice (relative path in `$PYTHONPATH`) and rather annoying (you need to be in a specific directory to run everything). Trying to automate that will sure end up in pure hell!<p>- As in &quot;you need to `cd` to _this_ directory then run _that_<p>- Or &quot;WTF it worked on my machine when I was in this directory but now it doesn&#x27;t&quot;
评论 #9778364 未加载
majke将近 10 年前
I&#x27;ll use the opportunity to moan about the state of packaging in the Python world. Why, after so many years, there is no way for me to ship software written in python, in deb format?<p>I end up doing some real crazy stuff:<p>* build in docker<p>* using virtualenv &#x2F;usr&#x2F;local&#x2F;mypackage<p>* then manually copy over the init scripts &quot;cp &#x2F;usr&#x2F;local&#x2F;mypackage&#x2F;bin&#x2F;* &#x2F;usr&#x2F;local&#x2F;bin&quot;<p>* and debianize &quot;&#x2F;usr&#x2F;local&#x2F;mypackage&#x2F;&quot; and &quot;&#x2F;usr&#x2F;local&#x2F;bin&quot;.<p>Except it doesn&#x27;t work:<p>* I need root do create the venv in &#x2F;usr&#x2F;local.<p>* This technique copies garbage like &quot;activate&quot; script to bin.<p>* virtualenv ships its own python binary. If the python version on host differ, it won&#x27;t work.<p>* The workaround is to rewrite the bin scripts.<p>Total mess. All I need is a deb with some bin scripts, and all dependencies bundled. Is it _that_ hard...
评论 #9778461 未加载
评论 #9778762 未加载
评论 #9778540 未加载
评论 #9779038 未加载
评论 #9779004 未加载
评论 #9778470 未加载
killerbat00将近 10 年前
&gt; Looking at Javascript, tools like npm and Bower provide the easy, reliable and powerful package management capabilities which it feels like Python is missing. The key to their success? Both tools download a copy of the right versions of the right libraries, by default placing them in a special folder directly within your project&#x27;s directory.<p>Isn&#x27;t this exactly what virtualenv does anyway? Plus, with virtualenv you don&#x27;t have to muck around in your $PYTHONPATH and you can still choose which Python version is installed for each virtualenv.<p>This article doesn&#x27;t seem to explicitly mention any, but what are the compelling reasons to use pip over pyenv&#x2F;virtualenv for project isolation? I guess using 1 tool to install dependencies and isolate your working environment is handy. I&#x27;m unsure if the overhead of virtualenv is so high that it offers a compelling reason to switch (at least for me).
publicfig将近 10 年前
I&#x27;d hardly consider virtualenv with virtualenvwrapper &quot;overkill&quot;. It&#x27;s a pretty elegant and incredibly easy solution to conflicting dependencies that is capable of being used on almost any other environment easily.
评论 #9778757 未加载
gdamjan1将近 10 年前
oh, it&#x27;s 2015 and people still don&#x27;t know about pep-370, PYTHONUSERBASE and pip install --user :(<p><a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0370&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0370&#x2F;</a>
评论 #9778621 未加载
评论 #9783212 未加载
deathanatos将近 10 年前
&gt; forget about source env&#x2F;bin&#x2F;active and deactivate!<p>If the activate&#x2F;deactivate bothers you, you can also just call the interpreter directly: env&#x2F;bin&#x2F;python ; you can also call any pip-installed binaries similarly. For example, env&#x2F;bin&#x2F;ipython if you have that installed. Or env&#x2F;bin&#x2F;pip.<p>I have a small utility[1] to magic that to &quot;vpython&quot; and &quot;vipython&quot; and &quot;venv pip&quot;, respectively. (The last one is the general &quot;execute this binary in the virtualenv&quot; form; the utility makes some assumptions about how you name your envs, however, but also searches up the tree (I can cd into a dir, so I don&#x27;t need to do ..&#x2F;..&#x2F;env&#x2F;bin&#x2F;python… or source the env.) I believe there&#x27;s another implementation of this idea out there, but I can&#x27;t find it at the moment.<p>(My vim is&#x2F;was a bit python-heavy, and sourcing envs utterly breaks it if I attempt to start vim with an env sourced, since it gets the right vimrc, but the wrong pip installation)<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;thanatos&#x2F;vpython" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thanatos&#x2F;vpython</a>
pbhowmic将近 10 年前
I started using pip -t ever since I started coding for AppEngine. I prefer it to a virtualenv becaus it works out a lot neater with the dev server. App engine&#x27;s earlier approach was to use either virtualenv or pull all the dependencies&#x27; code down into the project directory but lately, the App Engine team have started recommending using pip -t instead.
stefanha将近 10 年前
Careful using relative paths in PYTHONPATH.<p>If you share a file system with untrusted users (like &#x2F;tmp or an NFS mount) or extract an untrusted archive (zip, tar, rar) then you might inadvertently execute python code that another user placed there!<p>It&#x27;s the same reason why you shouldn&#x27;t use PATH=. in your shell.<p>This poor man&#x27;s virtualenv doesn&#x27;t seem like a good idea...
ptx将近 10 年前
This is a very bad idea, for the same reason that relative directories are not on the regular PATH on Unix: On a multi-user system, or even a single-user system that sometimes has untrusted files on it, you can&#x27;t safely use your tools if they can be overridden by whatever someone happens to have placed in the current directory.<p>For example, if you&#x27;re looking through various home directories for some file, you might be doing something like:<p><pre><code> $ cd &#x2F;home&#x2F;foo $ ls $ cd &#x2F;home&#x2F;bar $ ls </code></pre> If your PATH contained &quot;.useful_stuff&#x2F;tools&quot; and the user bar happened to have a file called &quot;&#x2F;home&#x2F;bar&#x2F;.useful_stuff&#x2F;tools&#x2F;ls&quot;, that file has now been executed instead of &#x2F;bin&#x2F;ls, with your privileges. Your account has now been compromised.<p>Try this:<p><pre><code> [ptx@hn downloads]$ python3 -c &#x27;print(&quot;hello&quot;)&#x27; hello [ptx@hn downloads]$ export PYTHONPATH=&quot;.&#x2F;.pip&quot; [ptx@hn downloads]$ python3 -c &#x27;print(&quot;hello&quot;)&#x27; You have been owned! Have a nice day. hello [ptx@hn downloads]$ cat .pip&#x2F;site.py print(&quot;You have been owned! Have a nice day.&quot;) </code></pre> For this same reason, if you use Mercurial on a repository owned by someone else, you get something like:<p><pre><code> [root@host foo]# hg stat not trusting file &#x2F;home&#x2F;ptx&#x2F;foo&#x2F;.hg&#x2F;hgrc from untrusted user ptx, group users </code></pre> Microsoft had a related security problem a few years back where they would load DLL files from the current directory: <a href="https:&#x2F;&#x2F;isc.sans.edu&#x2F;diary&#x2F;DLL+hijacking+vulnerabilities&#x2F;9445" rel="nofollow">https:&#x2F;&#x2F;isc.sans.edu&#x2F;diary&#x2F;DLL+hijacking+vulnerabilities&#x2F;944...</a>
AUmrysh将近 10 年前
This is a nice, simple solution to segregating python package environments. I personally prefer virtualenv, as I can navigate around the filesystem and open ipython from anywhere within the venv. I guess I don&#x27;t see the usefulness of it so much because I have no problem using virtualenv.<p>The relative path is an interesting trick, I&#x27;ll have to keep that in mind in the future.
erikb将近 10 年前
Since the packaging wars end of 2012 to beginning of 2013 I was following relatively closely packaging and requirements tracking, and let me say this: We don&#x27;t need another solution. We need the solution we have to work better. Pip+Virtualenv is enough to learn and handle and nowadays works well for most use cases. It&#x27;s maybe not perfect but it gets the job done. Problems I still see: Most of all integration with the system&#x27;s package manager; pip3 install -e will be overwritten by the corresponding pypi package if you increase the version, although the -e installed version is already the required one; sudo pip3 freeze doesn&#x27;t work, at least on the current Ubuntu.<p>There are so many little details that need to be fleshed out in such an infrastructure tool, we can&#x27;t solve all these boring problems multiple times.
thefreeman将近 10 年前
There is probably an obvious answer to this, but a cursory google search turned up no answers.<p>The idea of having different multiple versions of dependencies on a single system is not exactly a new problem, and is solved by <i>many</i> other package managers. Is there some inherent weakness in python modules that forces them to be managed this way? Do the maintainers of pip insist on this for other reasons?<p>It seems like one of the bigger complaints I hear about python so I feel like it must be harder then it seems.
评论 #9779655 未加载
goblin89将近 10 年前
IMHO complexity created by limited isolation facilities of virtualenv and the likes isn’t worth the resources you save by not just having a VM for each app you work on.<p>The complexity arises from differing system-wide dependencies that are out of scope of various package managers or virtual environments, and from development environment (assuming we’re addressing the need to have multiple apps co-exist on one machine for development) not matching production.
fizixer将近 10 年前
Not sure why it tries to replace virtualenv which is already obsolete in favor of pyvenv which is built-in.
评论 #9779181 未加载
wkornewald将近 10 年前
Also have a look at vex: <a href="https:&#x2F;&#x2F;github.com&#x2F;sashahart&#x2F;vex" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sashahart&#x2F;vex</a><p>Unlike this pip solution, vex extends your PATH to include installed scripts. It also works well on Windows and is really easy to use.
personjerry将近 10 年前
Isn&#x27;t it rather dangerous to have a &quot;transparent&quot; version of virtualenv?
w_t_payne将近 10 年前
This is somewhat similar to what I do ...
评论 #9778107 未加载
fit2rule将近 10 年前
Packaging: if you have to do it, you should be building a bootable, distributable, OS instead.<p>Doesn&#x27;t matter how many times others learn this lesson, I personally see it over and over.