简体   繁体   English

在Pycharm中安装Zipline模块有效,但是在尝试使用它时无效

[英]Installing the Zipline module in Pycharm works but it doesnt work when trying to use it

I have installed python 3.5 and 2.7 as project interpreters. 我已经安装了python 3.5和2.7作为项目解释器。 Whenever I install Zipline, it says that it is installed successfully, but I cant find it in the packages nor if I type in my python file 'import zipline...' 每当我安装Zipline时,它都说安装成功,但是我无法在软件包中找到它,也无法输入python文件“ import zipline ...”。

To answer this question, it would be beneficial if you state how you installed Zipline and which Python interpreter is being used for the project. 要回答这个问题,如果说明如何安装Zipline以及该项目使用哪个Python解释器,将是有益的。 Something else that could play a role in this is whether or not you are using a virtual environment, this can be checked by clicking terminal, then if it says (venv) before the line. 可能与此有关的其他因素是您是否正在使用虚拟环境,可以通过单击终端,然后在行前显示(venv)进行检查。

Update #1 更新#1

@cem When you create a project in Pycharm, it creates a virtual environment for that project. @cem在Pycharm中创建项目时,它将为该项目创建虚拟环境。 You can see if this is true by clicking "Terminal in the bottom left corner. The bottom line should look something like this: (venv) C:\\Users\\griff\\PycharmProjects\\untitled> Notice the (venv). 您可以通过单击“左下角的终端来查看是否正确。底线应类似于以下内容: (venv) C:\\Users\\griff\\PycharmProjects\\untitled>注意(venv)。

To find out what Python interpreter you are using for this project in Pycharm, open the terminal in Pycharm again. 要找出在Pycharm中用于此项目的Python解释器,请再次在Pycharm中打开终端。 and type python --version this will output what Python interpreter is being used. 并键入python --version将输出正在使用的Python解释器。

The way you should be installing packages in Pycharm is: 您应该在Pycharm中安装软件包的方式是:

1) Click the terminal again 1)再次单击终端

2) type pip install zipline 2)输入pip install zipline

This will install the package on your venv for Pycharm and you should be able to import them. 这将在您的venv上为Pycharm安装该软件包,您应该能够导入它们。

Update #2 更新#2

@cem The problem I believe, is that you are installing the library with a Python interpreter that you are not using on your Pycharm project. @cem我相信的问题是,您正在使用未在Pycharm项目上使用的Python解释器安装库。 One way to solve this is with a virtual environment. 解决此问题的一种方法是使用虚拟环境。 It is a good habit for Python developers to create virtual environments for their projects, and avoid global install of libraries. 对于Python开发人员来说,为他们的项目创建虚拟环境并避免全局安装库是一个好习惯。 So, it seems as though you are not using a virtual environment. 因此,似乎您没有使用虚拟环境。 To start a virtual environment in Pycharm follow this guide: https://www.jetbrains.com/help/pycharm-edu/creating-virtual-environment.html 要在Pycharm中启动虚拟环境,请遵循以下指南: https ://www.jetbrains.com/help/pycharm-edu/creating-virtual-environment.html

Then follow the steps to install the package again as I pointed out in Update 1. 然后按照我在Update 1中指出的步骤,重新安装该软件包。

UPDATE #3 更新#3

so this is not the best practices solution but at this point we just need to fix this. 因此,这不是最佳做法解决方案,但现在我们只需要解决此问题即可。 Open up your terminal and type python --version . 打开终端,然后输入python --version take note of the version. 记下版本。 then type either python3 pip install zipline or just pip install zipline whichever one works. 然后输入python3 pip install zipline或仅pip install zipline以其中一种有效。 After that open up Pycharm and make sure the Python interpreter you are using for that project is the same as the version that was returned when you typed python --version into terminal 之后,打开Pycharm并确保用于该项目的Python解释器python --version输入terminal时返回的版本相同。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM