I am trying to use the dygraphs plot function from [here] (https://github.com/dinkelk/PyDyGraphs) in my jupyter notebook. The documentation says to:
Installation
Simply clone this repository and include the dygraphs.graph module in >>your Jupyter Notebooks. Note: PyDyGraphs only supports Python 3.
The documentation says to use "import dygraphs.graph as dy"
I'm not sure where to put the repository once I've downloaded it.
The package I've downloaded and unzipped. I've included the "import dygraphs.graph" in my notebook.
This package requires pandas to be installed and imported which I have done.
import numpy as np
import dygraphs.graph as dy
_____
ModuleNotFoundError Traceback (most recent
call last)
<ipython-input-3-29a3c1e17595> in <module>
4 import pandas as pd
5 import time
----> 6 import dygraphs.graph as dy
ModuleNotFoundError: No module named 'dygraphs'
_____
I'm wondering where I should have put the files downloaded from github and if there is anything else I should be doing in order to use this package.
You need to add a system path (or install the package to the default python libary) before using "import dygraphs.graph". See the example .
Add something like this in your jupyter notebook:
sys.path.append("../")
Then change "../" to the relative path to "dygraphs" folder you downloaded.
Related
When I try importing functions and classes that I've created in Python scripts into a Jupyter Notebook, I get import errors. However, when I run the same code in a regular script rather than in a notebook, it runs without a problem.
All three files are in the same directory:
First, I have my_function_script.py, which defines functions.
def my_function():
pass
Second, I have my_class_script, which both imports the functions defines classes:
from my_function_script import my_function
class my_class():
pass
When I try to run the below import script in a Jupyter Notebook, I get an ImportError.
from my_class_script import my_class
ImportError Traceback (most recent call last)
<ipython-input-6-8f2c4c886b44> in <module>
----> 1 from my_class_script import my_class
~\my_directory\my_class_script.py in <module>
5
----> 6 from my_function_script import my_function
ImportError: cannot import name 'my_function' from 'my_function_script' (C:\Users\my_directory\my_function_script.py)
I believe that the problem is specific to the Jupyter Notebook for two reasons. First, I've confirmed that both my_function_script.py and my_class_script.py can run in the terminal without error. Second, when I take the same line that causes the Jupyter Notebook to error and run it in a regular Python script, it runs without error.
I have Windows, and I don't have multiple environments or versions of Python.
you can add to the Python path at runtime:
# some_file.py
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')
import file
this usually happens when your jupyter notebook does not point to the correct directory for importing
one way to fix this would be to change the working directory in jupyter notebook
import os
os.chdir('path/to/python/scripts/directory')
from my_class_script import my_class
another way to do this is using UNIX commands directly in jupyter notebook
cd /path/to/python_script_directory
from my_class_script import my_class
make sure you dont put the cd command and import statement in the same notebook block
I am importing keras_adversarial and cloning its git too but it cannot import 'AdversarialModel'
i am working on gans, built generator and discriminator. now i want to combine them but colab is giving error while importing the modules of keras_adversarial
import keras_adversarial
from keras_adversarial import AdversarialModel, simple_gan, gan_targets
from keras_adversarial import AdversarialOptimizerSimultaneous,
normal_latent_sampling
1 import keras_adversarial
----> 2 from keras_adversarial import AdversarialModel, simple_gan,
gan_targets
3 from keras_adversarial import AdversarialOptimizerSimultaneous,
normal_latent_sampling
ImportError: cannot import name 'AdversarialModel'
The Colab environment only have a core set of packages installed. To add some third-party packages as keras_adversarial, you can execute installation script direcrly in Colab cells, with ! symbol before each command to indicate that these are command line bash code, not Python.
In your case, you need to do:
!git clone https://github.com/bstriner/keras_adversarial.git
!cd keras_adversarial
!python setup.py install
I recently downloaded a package and when testing the package to see if everything works correctly I get the error ImportError: No module named 'cubicspline'. When following the trail to see where is error occurs I found that cubicspline.py (the file not being found) is in the same folder as extcurve_s16.py (the file calling cubicspline).
File "/Users/Austin/anaconda/lib/python3.5/site-packages/isochrones/schlafly/extcurve_s16.py", line 4, in <module>
import cubicspline
I've checked the permissions on the folder and I'm able to both read and write. There is also an __init__.py file in the folder. Any ideas here? I can't figure out why it wouldn't be able to call a file that is in the same folder. Here is the exact chunk of code for reference, as can be seen import numpy works fine.
import numpy
import cubicspline
The issue was resolved by cloning the isochrones package from Github instead of using pip install isochrones. There was some type of issue with the pip version.
I have a package that I would like to automatically install and use from within my own Python script.
Right now I have this:
>>> # ... code for downloading and un-targzing
>>> from subprocess import call
>>> call(['python', 'setup.py', 'install'])
>>> from <package> import <name>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named <package>
Then I can continue like this:
>>> exit()
$ python
>>> from <package> import <name>
And it works just fine. For some reason, Python is able to pick up the package just fine if I restart after running the setup.py file, but not if I don't. How can I make it work without having the restart step in the middle?
(Also, is there a superior alternative to using subprocess.call() to run setup.py within a python script? Seems silly to spawn a whole new Python interpreter from within one, but I don't know how else to pass that install argument.)
Depending on your Python version, you want to look into imp or importlib.
e.g. for Python 3, you can do:
from importlib.machinery import SourceFileLoader
directory_name = # os.path to module
# where __init__.py is the module entry point
s = SourceFileloader(directory_name, __init__.py).load_module()
or, if you're feeling brave that your Python path knows about the directory:
map(__import__, 'new_package_name')
Hope this helps,
I downloaded from seaborn from GitHub.
Through command prompt, cd to downloads\seaborn folder
python install setup.py
Then using spyder from anaconda, checked if it was installed by running the following in a console
import pip
sorted(["%s==%s" % (i.key, i.version)
for i in pip.get_installed_distributions()])
Seeing that it was not there, go to tools and select "Update module names list"
Again trying the previous code in a python console, the lib was still not showing.
Restarting Spyder and trying import seaborn worked.
Hope this helps.
I am trying to run this python rewrite of Vlfeat library.
https://github.com/shackenberg/phow_caltech101.py. I am trying to run the application phow_caltech101.
This is throwing
File "/A/B/C/pyvlfeat-0.1.1a3/vlfeat/__init__.py", line 1, in <module>
import _vlfeat
ImportError: No module named _vlfeat
In the corresponding "init.py" file, I can see it is mentioned as "import _vlfeat". I am new to python, please let me know what is causing this error?
You need to download and install PyVlfeat module.
https://pypi.python.org/pypi/pyvlfeat/
As I see, pyvlfeat has some dependencies, so be sure to download these too:
Boost.Python (tested against version 1.35.0-5)
NumPy (tested against version 1.5.1)
Matplotlib (tested against version 0.99.3)