当前位置: 首页 > 知识库问答 >
问题:

如何使用python3创建虚拟环境

徐佐
2023-03-14

我使用python 2.7虚拟环境版本1.10.1运行myproject项目。由于一些其他项目的要求,我必须使用Python的其他版本(Python 3.5)和Django 1.9。为此,我在我的用户目录中安装了python。此外,我已经下载并安装了虚拟环境(版本-15.1.0)到我的用户目录。但是每当我试图创建虚拟环境时,我都会遇到以下错误

python virtualenv/virtualenv.py myproject
Using base prefix '/home/myuser/python3'
New python executable in /home/mount/myuser/project_python3/myproject/bin/python
ERROR: The executable /home/mount/myuser/project_python3/myproject/bin/python is not functioning
ERROR: It thinks sys.prefix is '/home/myuser/python3' (should be '/home/mount/myuser/project_python3/myproject')
ERROR: virtualenv is not compatible with this system or executable

谁能告诉我我做错了什么

共有3个答案

祖新觉
2023-03-14

Python自3.3版以来已经附带了名为venv的内置“virtualenv”。您不再需要为Python 3.3安装或下载virtualenv脚本。

https://docs.python.org/3/library/venv.html

检查您的安装是否提供了pyvenv命令,该命令应负责创建“virtualenv”。参数类似于经典的virtualenv项目。

$ pyvenv --help
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.

伏默
2023-03-14

创建虚拟环境的步骤

virtualenv -p python3 venv_name 

这将在baseDirectory/bin/python3中创建新的python可执行文件

如何激活新创建的Venv:

cd baseDirectory/bin/  

source activate  

停用新venv

deactivate 

更新1

由于现在推荐使用venv来创建虚拟环境,因此该方法已被贬低。请检查此链接以获取更新的答案

惠泳
2023-03-14

在Python3.6中,pyvenv模块已被弃用。改用以下一个衬垫:

python3 -m venv <myenvname>

这是Python社区推荐的创建虚拟环境的方法

 类似资料:
  • 我使用python 2.7虚拟环境版本1.10.1运行myproject项目。由于一些其他项目的要求,我必须使用Python的其他版本(Python 3.5)和Django 1.9。为此,我在我的用户目录中安装了python。此外,我已经下载并安装了虚拟环境(版本-15.1.0)到我的用户目录。但是每当我试图创建虚拟环境时,我都会遇到以下错误 谁能告诉我我做错了什么

  • 我的系统正在运行CentOS 6。我没有管理员访问权限,所以sudo不可用。我有Python 2.7.3可用,以及和。我希望我可以使用这些来建立一个新的虚拟环境在其中安装 我尝试了这里描述的方法:在virtualenv中使用python3 但是得到了这个错误: 我的系统还安装了Python 3.4模块,因此我尝试了这一点,但virtualenv似乎无法在那里工作: 这似乎是有道理的,因为只有Pyt

  • 如何删除使用创建的虚拟环境 我可以删除目录吗? 这似乎是一个谷歌应该很容易回答的问题,但我只找到了删除用或创建的环境的答案。

  • 本文向大家介绍Win10里python3创建虚拟环境的步骤,包括了Win10里python3创建虚拟环境的步骤的使用技巧和注意事项,需要的朋友参考一下 1、为什么要用虚拟环境? 为了解决一个环境多个项目的版本冲突问题 2、如何创建虚拟环境? 用窗口键+R来打开win10的运行窗口,然后在运行输入框输入cmd,确认将会弹出一个终端界面。 创建一个目录,比如我起名为myproject,则在终端窗口输入

  • 问题内容: 如果我选择SELECT AS b且b不是表中的列,查询会创建“虚拟”列吗? 实际上,我需要将一些虚拟列合并到查询中,并将一些信息处理到查询中,以便以后可以在每个项目中使用它。 问题答案: 就像是: 这使您可以进行操作并将其显示为列。 编辑: 您还可以使用联接并将操作显示为列:

  • 本文向大家介绍快速创建python 虚拟环境,包括了快速创建python 虚拟环境的使用技巧和注意事项,需要的朋友参考一下   python安装第三方库大都是通过pip命令安装,这个命令确实是很简便的,而对于每个独立的项目来说,需要用到的库或许会不同,如果删除或更新原来已有的版本库,或许会导致其他的项目出错,这时候,虚拟环境就能够起作用了。哈哈~~~   所以呢,通过python创建虚拟环境,可以