0

I have created my project in virtual environment using Python 3.6. I used pip install virtualenv and has created my environment using the following command:

virtualenv venv

Now I have the folder called venv. I have installed everything and now willing to shift on another system.
So I just copied the folder and activated the environment which ran successfully.
Now I am trying to check the version of the pip but is it giving the following error:

C:\Users\aims\Desktop\venv\Scripts>activate

(venv) C:\Users\aims\Desktop\venv\Scripts>pip --version
Fatal error in launcher: Unable to create process using '"c:\users\jaffer\venv\scripts\python.exe"  "C:\Users\aims\Desktop\venv\Scripts\pip.exe" --version'  

I am puzzled as the virtual environment has everything and was working fin on the previous system. I guess the virtualenv didn't made the environment system independent.

Please suggest me how I can make the project portable or dockable from one system to another without loosing and environment.

EDITED:
I tried --relocatable Not working. Please tell me my pip is not working at all. Means something got missed.

Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
  • 1
    Possible duplicate of [How to use python virtual environment in another computer](https://stackoverflow.com/questions/26399754/how-to-use-python-virtual-environment-in-another-computer) – phd Dec 26 '18 at 13:02
  • https://stackoverflow.com/search?q=%5Bvirtualenv%5D+another+computer – phd Dec 26 '18 at 13:02
  • @phd I am not even able to know the version of `pip` how can I download the requirements from the requirements.txt? Please explain. And its not a duplicate btw. – Jaffer Wilson Dec 26 '18 at 13:04
  • [How to recreate a virtualenv](https://stackoverflow.com/a/43122954/7976758) – phd Dec 26 '18 at 13:06
  • @phd Sir please let me know if I try this `pip install -r requirements.txt` will my problem be solved as I when I tried `pip --version` I got the error specified in the question. – Jaffer Wilson Dec 26 '18 at 13:07
  • 1
    @JafferWilson: Generally speaking, virtualenv is most useful for *development*, when you can be developing or testing projects with different requirements on the same machine, as it ensures that the dependences of your project are correctly expressed. For *distribution* virtualenv isn't going to help you. You probably want to use the `setuptools` package to create a distributable version of your package, which you can then install on the target machine using something like `pip` (which might have to be installed separately, depending on how Python was installed on the target machine). – Daniel Pryden Dec 26 '18 at 13:10
  • 1st you have to remove the copied virtualenv, it doesn't work. Then you have to decide what you really want. Do you want to run python programs on the second computer or do you want to continue development. Python's virtualenvs are for development, not deployment. – phd Dec 26 '18 at 13:10
  • @phd I want to continue development. I want to know whether I can create a portable virtual environment or is there any other mechanism for that. Please let me know. – Jaffer Wilson Dec 26 '18 at 13:14
  • @JafferWilson: It *may* be possible to create a portable virtual environment. But you probably *shouldn't*. Virtual environments are intended to be somewhat ephemeral: to get the most benefit from one you should be in the habit of destroying and re-creating it from time to time anyway, and if you can do that reliably then you don't need to use the same one on multiple machines anyway. – Daniel Pryden Dec 26 '18 at 13:16
  • @JafferWilson No, virtualenvs are not portable. `pip freeze` + `pip install -r req.txt` is the way to recreate a virtualenv. – phd Dec 26 '18 at 15:04

1 Answers1

1

Your current working directory is inside C:\Users\aims which contains the python executable for virtualenv but as you can see after activating the virtualenv pip is looking for python executable in c:\users\jaffer which probably doesn't exists in this system you are currently working on. If your OS and System python version matches, you can probably use --relocatable switch while creating virtual environment, but

The --relocatable option currently has a number of issues, and is not guaranteed to work in all circumstances. It is possible that the option will be deprecated in a future version of virtualenv.

You can find more information here on the official documentation.

arryph
  • 2,725
  • 10
  • 15
  • 1
    The official documentation states that: > You can move the directory around, but it can only be used on other similar computers. Some known environmental differences that can cause incompatibilities: a different version of Python, when one platform uses UCS2 for its internal unicode representation and another uses UCS4 (a compile-time option), obvious platform changes like Windows vs. Linux, or Intel vs. ARM, and if you have libraries that bind to C libraries on the system, if those C libraries are located somewhere different (either different versions, or a different filesystem layout). – arryph Dec 26 '18 at 09:30
  • The system I have is Windows 10. I am using wndows only – Jaffer Wilson Dec 26 '18 at 09:31
  • Please let me know if there s any other way for doing what I am trying to achieve. – Jaffer Wilson Dec 26 '18 at 09:34
  • Running `virtualenv --relocatable` command on existing virtual environment should be enough to achieve your target, but it doesn't change `activate` script, you can run `python` or `pip` directly within the venv directory and test, work's perfectly for me. As both of your system is Windows, and I am guessing installed python version is also same, it should work. Try running the executables with Script directory directly with out activate script, should work. – arryph Dec 26 '18 at 10:24