So I am trying to import zipline with anaconda. Though due to the fact that zipline requires python 3.5 I created an environment with python 3.5 in it. I did conda install zipline in the environment's terminal and it says it has successfully installed, then when I open python within the environment, and I import zipline no errors come up. I also have jupyter notebook installed in the env, when I import zipline in ipython, it causes no errors. But then when I open Jupiter notebook through the environment, then open a new kernel and try to import zipline, it says the module does not exist (I have even imported numpy and other things that are also downloaded and they work fine in the same jupyter notebook tab, and I also I am opening JN through the 3.5 env terminal not the base terminal). Please help, thank you.
EDIT: An example of the code could be
import numpy as np
np.sqrt(16)
This will return:
4.0
Then if I import zipline:
!conda install -c quantopian zipline
import zipline as zp
import numpy as np
np.sqrt(16)
There is no output, it just skips to the next cell without an error popping up, and also the I[1] part of the cell changes to I[*] instead of I[2]
(I am new at python so probably I am doing something wrong)
what I get from pip show zipline in the terminal
Name: zipline
Version: 1.3.0
Summary: A backtester for financial algorithms.
Home-page: http://zipline.io
Author: Quantopian Inc.
Author-email: opensource#quantopian.com
License: Apache 2.0
Location: c:\users\benito\anaconda3\envs\env_zipline\lib\site-packages
Requires: pip, setuptools, Logbook, pytz, numpy, requests-file, scipy, pandas, pandas-datareader, patsy, statsmodels, python-dateutil, six, requests, Cython, cyordereddict, bottleneck, contextlib2, decorator, networkx, numexpr, bcolz, click, toolz, multipledispatch, MarkupSafe, Mako, sqlalchemy, alembic, sortedcontainers, intervaltree, lru-dict, empyrical, tables, trading-calendars
The first thing is it is required to install jupyter notebook for every environment. So at first make sure that you have installed jupyter notebook correctly on the required environment. If you have installed it correctly then open jupyter notebook and in a code cell write any one of the following commands and execute the cell.
!conda install -c quantopian zipline -y
or
!conda install -c quantopian/label/ci zipline -y
After this execution import the library again.
Related
I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.
I am new to jupyter notebooks and virtualenvironment. I think that I am incurring in a really trivial problem.
I am trying to import matplotlib in a Jupyter notebook and the import works fine. However, it uses the wrong version of the library (installed also systemwide) and I don't know how to force it to use the one in the virtualenvironment.
In my virtualenvironment I want to use a most recent version of matplotlib and therefore I did
pip install --upgrade matplotlib in my virtualenvironment. The upgrade worked fine.
Now if I do pip show matplotlib in my virtualenvironment I get:
Name: matplotlib
Version: 2.2.5
...
Instead, if I do the same command in my home, I get:
Name: matplotlib
Version: 1.5.1
However, if in my jupyter notebook I do
import matplotlib
print ("matplotlib version:",matplotlib.__version__)
I get:
('matplotlib version:', '1.5.1')
Could you please help me understanding what I do wrong?
I found a solution to my problem. First of all, I read this long post that I suggest to everyone using conda or pip.
Then I understood that the shell environment is determined when the Jupyter notebook is launched, while the Python executable is determined by the kernel, and the two do not necessarily match.
I understood this by putting at the beginning of my jupyter notebook the following:
paths = !type -a python
for path in set(paths):
path = path.split()[-1]
print(path)
!{path} -c "import sys; print(sys.path)"
print()
!type python
import sys
sys.executable
!pip show matplotlib
It showed me that I was still using an older version of the matplotlib library.
Therefore I added
!{sys.executable} -m pip install --upgrade matplotlib
Restarted my jupyter kernel and this solved my problem.
I hope this solution will help someone else in the same situation.
When using an Anaconda environment, I can't start Jupyter to work in a notebook. I can do so without the environment, but I need to be able to use the environment. Here's what I do and the errors I get:
ben#ben-K60IJ:~/surveillance_sound_classifier/surveillance_sound_classifier$ source activate EECS352
discarding /home/ben/anaconda/bin from PATH
prepending /home/ben/anaconda/envs/EECS352/bin to PATH
(EECS352)ben#ben-K60IJ:~/surveillance_sound_classifier/surveillance_sound_classifier$ jupyter notebook
Traceback (most recent call last):
File "/home/ben/anaconda/envs/EECS352/bin/jupyter-notebook", line 4, in <module>
import notebook.notebookapp
File "/home/ben/anaconda/envs/EECS352/lib/python2.7/site-packages/notebook/notebookapp.py", line 61, in <module>
from .services.contents.manager import ContentsManager
File "/home/ben/anaconda/envs/EECS352/lib/python2.7/site-packages/notebook/services/contents/manager.py", line 16, in <module>
from nbformat import sign, validate, ValidationError
File "/home/ben/anaconda/envs/EECS352/lib/python2.7/site-packages/nbformat/__init__.py", line 33, in <module>
from .validator import validate, ValidationError
File "/home/ben/anaconda/envs/EECS352/lib/python2.7/site-packages/nbformat/validator.py", line 21, in <module>
raise ImportError(str(e) + verbose_msg)
ImportError: No module named functools32
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
Yes, I've done pip install jsonschema and conda install jsonschema AND pip install functools32 and conda install functools32 from within the EECS352 environment to no avail; I arrive at an almost identical error, except this time, functools32 is replaced with _version.
I've reinstalled Anaconda, updated all its packages, created a new environment in the same way I created this one, and still I get this error. I'm using Ubuntu 15.10 32-bit. I used to be able to use this environment with no problems until roughly a week ago.
If this is a duplicate, please point me to the original; however, I haven't yet found anything that seems really relevant. The only thing that might be relevant is that this error did pop up after I modified some .conf file because I was having issues updating my computer's software using sudo apt-get upgrade. I don't recall what I had done and to which file, but if it's likely the source of this issue, I can spend some time trying to track it down. Please let me know if I should spend my time to do this, and I will.
I think I have a solution.
I did may things, regenerated my env (anaconda env) from another computer where it worked, but no success.
What I think that nailed it is upgrading jsonschema to 2.5.1
Here are my steps from "bad" jupyter env to working jupyter env.
Good luck and come back if it doesn't work, I will post the notebook* relevant versions.
>conda upgrade pip
pip: 8.1.0-py27_0 --> 8.1.1-py27_0
setuptools: 20.2.2-py27_0 --> 20.3-py27_0
>pip install functools32
Downloading functools32-3.2.3-2.tar.gz
Successfully installed functools32-3.2.3.post2
>jupyter notebook
ImportError: No module named _version
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
>pip install jsonschema
Requirement already satisfied
>pip install --upgrade jsonschema
Collecting jsonschema
Downloading jsonschema-2.5.1-py2.py3-none-any.whl
Successfully uninstalled jsonschema-2.4.0
Successfully installed jsonschema-2.5.1
>jupyter notebook
[I 16:45:41.708 NotebookApp] Writing notebook server cookie secret to
[I 16:45:42.134 NotebookApp] Serving notebooks from local directory:
[I 16:45:42.134 NotebookApp] 0 active kernels
[I 16:45:42.134 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
i also got the same error and none of the above mentioned procedures worked for me so i've checked the documentation of anaconda and found something useful
conda install -c conda-forge/label/cf201901 jsonschema
conda install jupyter
jupyter notebook
this worked for me,thanks to anaconda documentation
Re-install jsonschema solve the problem in my case:
$ pip uninstall jsonschema
...
$ pip install jsonschema
...
If any of the above mentioned solution didn't work then try this in your anaconda prompt: First run conda update -n root conda so you have the latest conda version installed. Then run conda update --all This will update all packages in the current environment to the latest version.
Even after installing jsonschema, your Jupyter Notebook might not run and give you the error:
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first
Then I suggest you to run the given two commands. It will solve your issue as it solved mine.
Try this from the terminal:
pip install ipython[notebook]
It worked for me, let me know if the problem still exists.
I had the same problem.
I solved it by running this command
conda install -c anaconda jsonschema
https://anaconda.org/anaconda/jsonschema
I solved it by just uninstalling and reinstalling python 3.7
Try this from terminal, it worked to me:
pip install --upgrade pyrsistent
I have recently started using Python 3.5 and Anaconda on my Windows pc. I am trying to plot a map. However, When I am in my Jupyter notebook and i type the command
import mpl_toolkits.basemap
I get an error message saying 'no module name' 'mpl_toolkits.basemap'
However, I have the module downloaded and in the same C:\Users\Geena file as my .matplotlib, .ipython, .jupyter files, etc.
Anyone know how I can fix this?
I've had this issue with anaconda on my windows 7.
I found the way to fix it with python 3.5:
You need to run with administrator rights "Anaconda Prompt" and in "Anaconda Prompt" run following command:
conda install -c conda-forge basemap-data-hires=1.0.8.dev0
, it will show new packages that you need to install and will ask you to install it - say 'Yes'.
After that new packages will be installed and the issue "import mpl_toolkits.basemap" will be fixed.
Thank you.
Currently, basemap is not compatible with python 3 for windows users. So, if you try conda install basemap and you have python 3 installed in windows, you'll see a message pointing out that a conflict was found with python 3.
I solved this by installing a python 2.7 environment. Try this:
http://conda.pydata.org/docs/py2or3.html
Then you just activate the python 2 environment. For example: activate py27 (py27 is the identifier of my python 2.7 environment).
After that, you can run conda install basemap with no conflict.
I'm using python 3.6.4 on Windows 7 Family Premium (32bit).
Because I was a bit frustrated by the message "no module named 'mpl_toolkits.basemap'", I searched for and tried a dozen of solutions without success : various versions, building from source, problems with VS version, nmake, ... You all know what I mean ;-)
I finally found a quite simple solution that works perfectly well for me :-) Here it is !
from here I downloaded basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I changed the current dir to my download dir
I installed the wheel with python -m pip basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I did the same for matplotlib‑2.2.3‑cp36‑cp36m‑win32.whl
You DO read the versions correctly : matplotlib 2.2.3 and basemap 1.1.0
Everything works fine for me and I finally can plot OSM POI's on a map of Belgium, without any 'trickery' at import :
import requests # to fetch OSM data
import json # to get the response
from mpl_toolkits.basemap import Basemap # ... Belgium is there !
import numpy as np # for arrays
import matplotlib.pyplot as plt # to build the populated map
Big big thanks to Christoph Gohlke (Danke Dir Christoph !) who did all the wonderful job !
When you have Anaconda, you don't download modules anywhere. In your command prompt, you type
conda install basemap
and it is installed with all its dependencies.
Anaconda requires an unusual install command for basemap 1.0.7.
https://anaconda.org/anaconda/basemap
To install this package with conda run:
conda install -c https://conda.anaconda.org/anaconda basemap
I just had this issue as well. All you need to do is update matplotlib by doing the following:
pip install --upgrade matplotlib
mpl_toolkits is part of matplotlib and just needs to be updated.
If you're using anaconda, the easiest thing to do is described here: in the conda prompt (as admin), type conda install -c anaconda basemap.
For people of the future : "Basemap is deprecated in favor of the Cartopy project."
https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement
I was trying to use the lmfit package for doing nonlinear least squares fit and I notices that the Canopy curated version is really old and doesn't have most of the objects. So I followed the instructions here https://support.enthought.com/entries/23389761 as I have done before no problem:
pip install --upgrade setuptools
pip install --upgrade lmfit
Now when I execute the same exact code some "import" statements (I suppose those involved with scimath) give:
ImportError: cannot import name scimath
Seems python standard library imports are fine e.g. import os.
I'm on Ubuntu Linux 14 with Canopy 1.5.2
What happened and how can I fix it and avoid breaking it again.
I solved the problem but I am still not sure why this occurred originally. I went into the package manager and uninstalled scimath reinstalled it and did explicit kernel restarts on my IPython notebooks and interpreters. This fixed it but I don't see why unless somehow the scimath installation was corrupted. Before that I tried restarting application, computer, and reinstalling canopy.