i am going crazy with an import problem. It should be 'simple' because i have a script (test2.py) with this import inside:
from jinja2 import Environment, FileSystemLoader, PackageLoader,select_autoescape
def myfun(arg1)
...
env = Environment(loader=FileSystemLoader('/var/www/html/templates'),autoescape=select_autoescape(['html', 'xml']))
...
Note that this script test2.py is called by test1.py (called by a CGI scripr) like that :
import test2
test2.myfun(arg1)
then i get the error:
from jinja2 import Environment, FileSystemLoader, PackageLoader, select_autoescape
ImportError: cannot import name 'select_autoescape'
the crazy thing is that if i call (directly) another script with these imports:
from jinja2 import Environment, FileSystemLoader, PackageLoader,select_autoescape
it goes fine! it does import the select_autoescape thing ...
So my question is why does it not import it when i call it from another function/module?
Try reinstalling jinja2:
sudo pip3 install --upgrade jinja2
It worked for me.
Related
On a Linux PC, I am attempting to create a custom open AI Gym environment. I can get through all of the steps from a blog write up from medium.com including the pip install -e . but I get an error with the final product making the environment env = gym.make('BASoperator-v1.0')
The medium blog states this file directory is needed, my naming convention is this:
vavBox/
README.md
setup.py
vavBox/
__init__.py
envs/
__init__.py
vavBox.py
This is my setup.py:
from setuptools import setup
setup(name='vavBox',
version='0.0.1',
install_requires=['gym']
)
First init.py:
from gym.envs.registration import register
register(
id='vavBox',
entry_point='vavBox.envs:vavBox',
)
2nd init.py in the env folder:
from vavBox.envs.vavBox import vavBox
The pip install went fine. I can see that pip installed the 3rd party package. But, when I attempt to import the environment thru this script below:
import numpy as np
import pandas as pd
import time
import gym
import vavBox
env = gym.make('vavBox')
I get an error, gym.error.Error: Attempted to register malformed environment ID: vavBox. (Currently all IDs must be of the form ^(?:[\w:-]+\/)?([\w:.-]+)-v(\d+)$.)
In vavBox/init.py the id should read:
from gym.envs.registration import register
register(
id='vavBox-v0',
entry_point='vavBox.envs:vavBox', )
or something with a "-v[0-9]+" after it to match the regex
I am trying to run the chatbot on windows 10. Python version I am using is Python 3.6.6. I installed rasa-core using pip3 install rasa_core and the installation was completed.
But every time I run my code, I get ImportError: No module named rasa_core.policies.keras_policy.
here are the import libraries:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import logging
import warnings
import csv
import pandas as pd
import unicodedata
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core import utils
from rasa_core.actions import Action
from rasa_core.actions.forms import FormAction
from rasa_core.agent import Agent
from rasa_core.channels.console import ConsoleInputChannel
from rasa_core.events import SlotSet
from rasa_core.events import AllSlotsReset
from rasa_core.featurizers import (
MaxHistoryTrackerFeaturizer,
BinarySingleStateFeaturizer)
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_nlu.model import Metadata, Interpreter
How can I get rid of Import Errors related to rasa-core?
What version of rasa-core are you using?
For e.g. on my mac Below are versions.
pip freeze |grep -i rasa
rasa-core==0.8.2
rasa-core-sdk==0.11.4
rasa-nlu==0.11.4
for rasa-core==0.8.2 class KerasPolicy is in
python3.6/site-packages/rasa_core/policies/keras_policy.py.
Hence you would import it using,
from rasa_core.policies.keras_policy import KerasPolicy
However, if you are using latest version rasa-core. for e.g.
pip freeze |grep -i rasa
rasa-core==0.12.0a3
rasa-core-sdk==0.11.4
rasa-nlu==0.13.3
Then class KerasPolicy is in
/python3.6/site-packages/rasa_core/policies/keras_policy.py .
Hence you would import it using
from rasa_core.policies.keras_policy import KerasPolicy
It appears that you are using an older version of rasa-core and trying newer versions based example.
You need to upgrade both rasa-core and rasa-nlu.
Here's link to latest requirement.txt that you can download.
After that simply run following to get dependencies installed along-with rasa-core and rasa-nlu.
pip install -r requirement.txt
I've deployed my application to AWS Lambda with Zappa. The deployment went fine without any issues. But when I try to reach the app via AWS API Gateway I get a 500 response.
The logs says
Unable to import module 'handler': No module named builtins
The environment runs on Python 2.7. I've added future to the Pipfile but it still won't work.
When I check the code in Lambda I can see the following code
from __future__ import unicode_literals
import base64
import boto3
import collections
import datetime
import importlib
import inspect
import json
import logging
import os
import sys
import traceback
import zipfile
from builtins import str
I can't find what can be wrong. Does anyone have a clue?
I solved the problem. I'm using pipenv to install my packages, but for some reason the packages wasn't installed inside the virtual environment, which made Zappa to not include them to AWS Lambda. I had to install them manually in PyCharm by going through Settings > Project > Project Interpreter and add the packages there. Thanks for your help.
I have made python package from
https://github.com/raamana/pyradigm
and uploaded it to pip using the following commands (after following the instructions on pypi, etc):
python setup.py sdist bdist_wheel
twine upload dist/*
In theory, now one should be able to do
pip install pyradigm
(which I can confirm works) and then do the following in a Python file:
from pyradigm import MLDataset
to use the class MLDataset from pyradigm
Unfortunately it's not the case, as Python is throwing the following ImportError which is fairly non-specific:
In [1]: from pyradigm import MLDataset
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4ad7330da13e> in <module>()
----> 1 from pyradigm import MLDataset
ImportError: cannot import name MLDataset
I can confirm that
I was able to install pyradigm via pip on a new system
both pip and python are able to find the package (installed in site-packages), as they auto-fill both the module name (pyradigm and class name MLDataset).
The setup.py in pyradigm is this:
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
# Utility function to read the README file.
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(name='pyradigm',
version='0.1.1.2',
description='Python-based data structure to improve handling of datasets in machine learning workflows',
long_description=read('README.md'),
keywords='machine learning, test dataset, python, workflow, provenance, data structure',
author='Pradeep Reddy Raamana',
url='https://github.com/raamana/pyradigm',
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), # packages=['pyradigm'],
install_requires=['numpy', 'setuptools'],
)
The package has only 3 files:
__init__.py pyradigm.py test_pyradigm.py
with the __init__.py containing the only a single line:
__all__ = [ 'pyradigm', 'MLDataset' ]
Any help in understanding in this error, and ways to fix it would be appreciated. Thanks.
It's because you have a pyradigm module inside a pyradigm package.
I've installed the package in a virtualenv using pip install pyradigm and successfully imported MLDataset with
from pyradigm.pyradigm import MLDataset
If you want to import as
from pyradigm import MLDataset
update your __init__.py to
from pyradigm import MLDataset
Trying to import safemine from cherrypy
from cherrypy import safemime
ImportError: cannot import name safemime
Cherrypy is installed with PIP ie.
sudo pip install -U cherrypy
According to cherrypy-users mailing list, safemime module was removed:
That module was removed in http://www.cherrypy.org/changeset/2319
because its functionality was folded into the new _cpreqbody.py
module.