Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Error: from quantopian.algorithm import attach_pipeline, pipeline_output

Hi - I am trying to write my first algorithm and am getting the following error when I run:

from quantopian.algorithm import attach_pipeline, pipeline_output

ImportErrorTraceback (most recent call last)
in ()
----> 1 from quantopian.algorithm import attach_pipeline, pipeline_output

/build/src/qexec_repo/qexec/algo/safety.py in call(self, name, globals, locals, fromlist, level) 262 # this is a whitelisted import
263 return self._import_safety.make_safe(
--> 264 self._import(name, globals, locals, fromlist, level),
265 )
266

ImportError: No module named algorithm

Any thoughts on what I am doing wrong? Thanks in advance!

3 responses

Include a backtest with your request if at all possible. If you can get a backtest to run, even by commenting out chunks of code, it makes it much easier for the community to provide help.

Your statement, below, is correct:

from quantopian.algorithm import attach_pipeline, pipeline_output

You should then be able to use these two methods in your code.

# Create and attach pipeline to get data  
 attach_pipeline(my_pipeline(context), name='my_pipeline')  
# Get the data  
context.output = pipeline_output('my_pipeline')  

You can also use the built in debugger in the IDE to help. See https://www.quantopian.com/help#debugger. Often times the problem is with the line just before the one being called an error.

Also, it wasn't mentioned if this is used in the IDE or Research environment? Maybe check this out if you are trying this in research? https://www.quantopian.com/posts/research-notebook-importerror-no-module-named-algorithm

Thank you