python - 无法将库安装到虚拟环境中
问题描述
我使用 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 在 virtualenv 中安装”但是这里的解决方案是不使用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 而不是全局路径?
解决方案
推荐阅读
- pusher - Pusher 私人聊天适用于本地主机,不适用于实时服务器
- java - 在 Jboss 模块和项目依赖项之间选择一个库版本
- python-3.x - 使用 pytest,我如何模拟 pathlib 的 Path.isdir() 函数和 os.listdir
- intellij-idea - 如何在 Intellij 编辑器中实现非侵入式 UI 元素
- arrays - MongoDB 不允许跨文档复制数组
- node.js - 子进程和异步编程的概念在 Node.js 中是否相同?
- java - 登录后重定向到自定义网址
- java - 错误 Swagger - 无法解析参考
- wordpress - Wordpress 多语言插件子目录 lanauge
- javascript - 尝试使用 tsc file.ts 运行 Typescript 时出现 WebGL2RenderingContext 错误