0

I have Anaconda with Python 3.6.4 install on a pc without an internet connection.

I want to use virtualenv to create a new environment. I thought that virtualenv c:\proj\myNewEnv will create a new virtual environment which is just like my base installation and inside this environment I can install more packages.

It seems I miss understood how it works.

In my base installation I have "TensorFlow" importing just fine. After running "virtualenv c:\proj\myNewEnv" I got a new folder named "c:\proj\myNewEnv" and inside it, I have directory "Scripts" with python.exe and activate.bat.

But no matter what I run, I am getting a python shell that does not know tensorflow.

It seems it is just a copy of my python.exe and pip.exe without all the original packages.

Is there a way to create a virtual environment that is a copy of my original or depend on my original installation (remember, I don't have an internet connection)?

Thanks in advance.

Nick
  • 3,454
  • 6
  • 33
  • 56
ZoRo
  • 401
  • 2
  • 5
  • 12

2 Answers2

0

You can see a few interesting options when you run

python -m virtualenv --help
Usage: virtualenv.py [OPTIONS] DEST_DIR

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity.
  -q, --quiet           Decrease verbosity.
  -p PYTHON_EXE, --python=PYTHON_EXE
                        The Python interpreter to use, e.g.,
                        --python=python3.5 will use the python3.5 interpreter
                        to create the new environment.  The default is the
                        interpreter that virtualenv was installed with
                        (/usr/sbin/python)
  --clear               Clear out the non-root install and start from scratch.
  --no-site-packages    DEPRECATED. Retained only for backward compatibility.
                        Not having access to global site-packages is now the
                        default behavior.
  --system-site-packages
                        Give the virtual environment access to the global
                        site-packages.
  --always-copy         Always copy files rather than symlinking.
  --relocatable         Make an EXISTING virtualenv environment relocatable.
                        This fixes up scripts and makes all .pth files
                        relative.
  --no-setuptools       Do not install setuptools in the new virtualenv.
  --no-pip              Do not install pip in the new virtualenv.
  --no-wheel            Do not install wheel in the new virtualenv.
  --extra-search-dir=DIR
                        Directory to look for setuptools/pip distributions in.
                        This option can be used multiple times.
  --download            Download pre-installed packages from PyPI.
  --no-download, --never-download
                        Do not download pre-installed packages from PyPI.
  --prompt=PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --setuptools          DEPRECATED. Retained only for backward compatibility.
                        This option has no effect.
  --distribute          DEPRECATED. Retained only for backward compatibility.
                        This option has no effect.
  --unzip-setuptools    DEPRECATED.  Retained only for backward compatibility.
                        This option has no effect.

Chief among them is --system-site-packages which Give[s] the virtual environment access to the global site-packages..

Give it a shot.

edd
  • 1,307
  • 10
  • 10
0

I wrote a long answer here : Does a python virtual environment avoid redundant installs?

In summary you can use the pip freeze > requirements.txt command from your base virtual environement, and install the new one by doing pip install requirements.txt.

If you want tenserflow and all dependecies from one environment be available into another one : pip freeze and pip install commands are your friends

Now remember : when you activate a virtual environment, you will see the (venv) (or whatever name you gave to it) at the begining of the prompt.

This mean that every package you'll install (pip install numpy for exemple) will be available for this particular environment. If you deactivate and switch to another venv, you'll need to install it again.

Also, when you activate an virtual environement, whenever you execute a python file, this will call the interpreter of this environment (if there is one) with all the dependencies you installed in it.

So in your case, make sure you first activate the venv, installed your dependencies, and execute your file

Now last thing : if you use Anaconda...you can do the same way with Anaconda specific commands :

conda list --export > requirements.txt 

And then :

conda create --name <envname> --file requirements.txt

Please check this question out for further explanation : Difference between pip freeze and conda list

Hope this will help

jossefaz
  • 3,312
  • 4
  • 17
  • 40