简体   繁体   English

为什么venv引用不同的python版本

[英]why does venv reference different python version

I followed djangogirls tutorial to get started with django and had everything working. 我遵循djangogirls教程来开始使用django,并使所有功能正常运行。 Once I finished the basic tutorial, everything in working order, I decided to go through the steps again to make something new and become more familiar with using git, django, venv, etc. 一旦完成了基础教程,一切都按部就班,我决定再次执行这些步骤以制作新内容,并变得更加熟悉使用git,django,venv等。

fyi - I am on windows 10 and have python 2.7 and python 3.5 installed. 供参考-我在Windows 10上并安装了python 2.7和python 3.5。 I am using python 3.5.2 with django 1.10.4. 我正在将Django 3.0.4和python 3.5.2一起使用。

steps: 脚步:

>mkdir v2
>cd v2
>"d:/python 3.5.2/python" -m venv myenv
>cd myenv/scripts/activate
(myenv) python -m pip install -U pip

for some reason this is the only way I was able to upgrade pip this time around 由于某种原因,这是我这次能够升级点数的唯一方法

(myenv) d:/v2/myenv/scripts> pip install django~=1.10.0
(myenv) d:/v2/myenv/scripts> django-admin.py startproject mysite

This is where the magic doesn't happen: 这是魔术不会发生的地方:

d:\v2>django-admin.py startproject mysite2
Traceback (most recent call last):
  File "D:\v3\myenv\Scripts\django-admin.py", line 2, in <module>
    from django.core import management
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",         line 10, in <module>
    from django.apps import apps
  File "C:\Python27\lib\site-packages\django\apps\__init__.py", line 1, in     <module>
    from .config import AppConfig
  File "C:\Python27\lib\site-packages\django\apps\config.py", line 4, in     <module>
    from django.core.exceptions import AppRegistryNotReady,     ImproperlyConfigured
  File "C:\Python27\lib\site-packages\django\core\exceptions.py", line 5, in <module>
    from django.utils.encoding import force_text
  File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 11, in <module>
    from django.utils.six.moves.urllib.parse import quote, unquote
  File "C:\Python27\lib\site-packages\django\utils\six.py", line 92, in     __get__
    result = self._resolve()
  File "C:\Python27\lib\site-packages\django\utils\six.py", line 160, in     _resolve
    module = _import_module(self.mod)
  File "C:\Python27\lib\site-packages\django\utils\six.py", line 82, in     _import_module
    __import__(name)
  File "C:\Python27\lib\urllib.py", line 26, in <module>
    import socket
  File "C:\Python27\lib\socket.py", line 47, in <module>
    import _socket
ImportError: Module use of python35.dll conflicts with this version of Python.

As far as I am aware, I followed the same steps. 据我所知,我遵循了相同的步骤。 I am not sure why the djano installed in my venv would be referencing python 2.7, since I thought if created my venv from the python 3.5.2 dir it would reference that version, along with anything I used pip for within that dir? 我不确定为什么安装在venv中的djano会引用python 2.7,因为我认为如果从python 3.5.2目录创建venv,它将引用该版本,以及我在该目录中使用pip的任何内容?

Can someone help me find what I am missing here? 有人可以帮我在这里找到我所缺少的吗? ty. ty。

By default virtualenv uses python2. 默认情况下,virtualenv使用python2。 If you want to use python3, you have to specify it explicitly. 如果要使用python3,则必须明确指定它。

Run following command to setup virtualenv with python3: virtualenv -p python3 envname 运行以下命令以使用python3设置virtualenv: virtualenv -p python3 envname

While in "Python 3.5.2/scripts" I ran: 在“ Python 3.5.2 / scripts”中,我运行了:

virtualenv d:/<dirname>

Everything after(django-admin.py startproject projectname) worked correctly. 之后的所有内容(django-admin.py startproject projectname)均正常运行。 Still not sure what went wrong here but maybe this helps someone else... 仍然不确定这里出了什么问题,但这也许可以帮助其他人...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 Pipenv 找不到适合我的 venv 的 python 的正确版本? - Why can't Pipenv find the correct version of python for my venv? 升级pycharm venv python版本 - Upgrading pycharm venv python version Python venv 文件夹究竟是如何工作的? 我的项目使用依赖项到这个 venv 文件夹中,使用不同的 Python 版本执行项目? - How exactly works Python venv folder? My project use the dependencies into this venv folder executing the project using a different Python version? 其中 python 与 venv 不同 - which python different than venv 为什么我的 venv 使用的 pip 版本与我安装的不同 - Why is my venv using a different pip version than I have installed 为什么我的 WSL Ubuntu 指向不同的 Python 版本? - Why does my WSL Ubuntu point to a different Python Version? 为什么pip会根据python版本升级到不同版本? - Why does pip upgrade to different versions depending on python version? 如何在标准库中的 venv 中使用不同的 Python 版本? (不是 virtualenv!) - How do I use different Python version in venv from standard library? (Not virtualenv!) 为什么 virtualenv(版本 20)比 python3 -m venv 快得多 - why virtualenv (version 20) is much faster than python3 -m venv Python 仍然使用默认版本而不是 Venv - Python still use default version not Venv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM