0

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. How I can assure that if someone pulls this project, they will only use the provided python library, and not their own python.
  2. Is this a correct approach to create a virtualenv, and push the entire project (including the virtualenv) to the cloud?

Here are some more info:

├── 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
Azim
  • 1,596
  • 18
  • 34
  • As an alternative: if you have an explicit (C)Python dependency, you may be better off packaging it as a Conda package. – 9769953 Oct 17 '18 at 13:48
  • 1
    My answer to question to would be "no". Specify any dependencies in another way, or just try to completely avoid them (do you *really* require a specific Python version? What version exactly, and why?). – 9769953 Oct 17 '18 at 13:49
  • If you activate our local environment it will try to fetch pip packages from local, if package not found on local environment it will take it from global. You can create a requirments.txt including all the pip packages. Everyone who make a clone of our project will just do a pip install on local environment – Lavanya Pant Oct 17 '18 at 13:51
  • @LavanyaPant all of those packages were installed using a local pip. The requirements.txt file is also there but I only posted a summarized list. – Azim Oct 17 '18 at 13:58
  • 1
    @Azim We should avoid push virtual env to git. If someone want to install it locally he/she should create virtual env and install your package. – Lavanya Pant Oct 17 '18 at 14:06

1 Answers1

2
  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.

  2. 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.

phd
  • 82,685
  • 13
  • 120
  • 165