首页 > 解决方案 > 无法将库安装到虚拟环境中

问题描述

我使用 Pycharm 和 Anaconda 为 Django 项目创建了虚拟环境。问题是我无法将 django-haystack 库安装到虚拟环境中。我尝试使用 anaconda、pycharm 本身安装它并尝试使用pip install django-haystack. 使用 pip install 我可以看到该库已安装。

Installing collected packages: django-haystack
Successfully installed django-haystack-2.8.1

我之前看到帖子有类似的问题,其中库安装在 python 中“[ Python 包没有使用 pip 在 vi​​rtualenv 中安装”但是这里的解决方案是不使用sudo安装库,但我没有使用它。

有人知道如何将这个库安装到虚拟环境中吗?我在 Windows 上运行一切

关于问题的更新

使用 pip freeze 输出我可以看到 django-haystack 已安装:

Django==2.1
django-haystack==2.8.1
elasticsearch==6.3.0

但是我仍然运行py -3 manage.py startapp search我得到这个错误:

ModuleNotFoundError: No module named 'haystack'

这是我的 settings.py 文件的外观:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'haystack'
]

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'localhost:9200',
        'INDEX_NAME': 'haystack',
    },
}

py -3 -m site输出:

sys.path = [
    'C:\\Users\\Joha\\PycharmProjects\\untitled1',
    'C:\\Python\\python36.zip',
    'C:\\Python\\DLLs',
    'C:\\Python\\lib',
    'C:\\Python',
    'C:\\Python\\lib\\site-packages',
]
USER_BASE: 'C:\\Users\\Joha\\AppData\\Roaming\\Python' (doesn't exist)
USER_SITE: 'C:\\Users\\Joha\\AppData\\Roaming\\Python\\Python36\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True

其中 pip 输出: C:\Users\Joha\Anaconda3\envs\test_haystack\Scripts\pip.exe C:\Python\Scripts\pip.exe 其中 py 输出: C:\Windows\py.exe

好的,问题是 pip 有两条路径。如何删除其中一条路径,使其仅使用 virtenv 而不是全局路径?

标签: pythondjangovirtualenvdjango-haystack

解决方案


推荐阅读