Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

python - Installing python3 in a python2 virtual environment

I have a Flask application that is running in a Python 2 virtual environment.

I'm looking to run a Python 3 program, so I need to install python3 into the virtual environment. How do I do this? Do I have to recreate the environment? Is this a difficult migration?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's not recommended to mix multiple versions of Python. In fact, I don't think it's even possible.

Creating a new virtualenv isn't difficult at all:

  1. Get the list of modules in the current virtualenv

    source /path/to/current/bin/activate
    pip freeze > /tmp/requirements.txt
    
  2. Create a new virtualenv. Either change into a suitable directory before executing the virtualenv command or give a full path.

    deactivate
    virtualenv -p python3 envname
    
  3. Install modules

    source envname/bin/activate
    pip install -r /tmp/requirements.txt
    

That's it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...