为什么virtualenv被拉后依赖于全局python而不是本地python? [英] Why virtualenv relies on the global python instead of the local one, after being pulled?

查看:28
本文介绍了为什么virtualenv被拉后依赖于全局python而不是本地python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拉 (git) 一个 python 项目,该项目是使用 virtualenv 创建的(由我在另一台计算机上).因此,python 库实际上位于该项目的本地目录中(例如,fila_env/bin/python).拉动它后,我可以找到它(见下面的树).但是,当我激活环境(使用 source fila_env/bin/activate)时,正在使用这台机器上的 python 而不是 virtualenv:

I pulled (git) a python project which was created (by me on another computer) using virtualenv. So, the python library is actually in a local directory (e.g., fila_env/bin/python) in this project. After pulling it, I can locate that (see the tree below). However, when I activate the environment (using source fila_env/bin/activate), the python on this machine is being used instead of the virtualenv's:

(fila_env) username@ASCSC-645A:~/CODES/.../myProject$ which python
>>> /usr/bin/python

我用谷歌搜索,但找不到一个好的解决方案.我想知道:

I googled around but I couldn't find a good solution to this. I would like to know:

  1. 我如何保证如果有人拉动这个项目,他们只会使用提供的 python 库,而不是他们自己的 python.
  2. 这是创建 virtualenv 并将整个项目(包括 virtualenv)推送到云端的正确方法吗?

以下是更多信息:

├── yyyyyyExample.py
├── fila_env
│   ├── bin
│   │   ├── activate
│   │   ├── ...
│   │   ├── python
│   │   ├── python2 -> python
│   │   ├── python2.7 -> python
│   │   ├── python-config
│   │   ├── ...
│   │   └── wheel
│   ├── include
│   │   └── python2.7 -> /usr/include/python2.7
│   ├── lib
│   │   └── python2.7
│   ├── local
│   │   ├── bin -> .../fila_env/bin
│   │   ├── include -> .../fila_env/include
│   │   └── lib -> .../fila_env/lib
│   ├── pip-selfcheck.json
│   └── share
│       ├── jupyter
│       └── man
└── xxxxxxExample.py

推荐答案

  1. 你不能也不应该,如果我使用 32 位 Linux 并且你的 virtualenv 是在 64 位 Windows 上创建的(反之亦然)你的 python 二进制文件肯定对我不起作用.

  1. You cannot and you shouldn't, If I use 32-bit Linux and your virtualenv has been created on 64-bit Windows (or vice versa) your python binary certainly will not work for me.

再说一遍,不.virtualenv 是开发人员的工具,而不是分发工具.对于分发,您应该考虑 sdist/egg/wheel,或创建依赖于平台的带有 PyInstallerpy2exe 或类似工具.

Again, no. virtualenv is a developer's tool, not a distribution tool. For distribution you should consider sdist/egg/wheel, or creating platform-dependent binaries with PyInstaller, py2exe or similar tools.

这篇关于为什么virtualenv被拉后依赖于全局python而不是本地python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆