Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import module 'handler': No module named werkzeug.wrappers #64

Open
chennav opened this issue Apr 20, 2016 · 34 comments
Open

Comments

@chennav
Copy link

chennav commented Apr 20, 2016

I tried installing Werkzeug but it seems like it is already installed
~/dev/testzappa% sudo pip install Werkzeug Requirement already satisfied (use --upgrade to upgrade): Werkzeug in /usr/lib/python2.7/site-packages

I guess it isn't packaged into the lambda.
I get the following error in my lambda cloudwatch logs
Unable to import module 'handler': No module named werkzeug.wrappers

@Miserlou
Copy link
Owner

Zappa needs to be used in a virtualenvironment. You shouldn't use sudo and pip together.

@chennav
Copy link
Author

chennav commented Apr 20, 2016

well, I've tried it out in a virtualenv, still get the same error.
Here's what I did,

  1. Created a new EC2 instance, installed pip and virtualenv
  2. Copied credentials to ~/.aws/credentials.
  3. [ec2-user@trialinstance dev]$ virtualenv testzappa
  4. [ec2-user@trialinstance dev]$ source testzappa/bin/activate
  5. Installed zappa (testzappa)[ec2-user@trialinstance dev]$ pip install zappa
  6. cd testzappa and Added demo code to my_app.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()
  1. Added zappa_settings.json
{
    "dev": {
       "s3_bucket": "test_app_deployment",
       "app_function": "my_app.app",
       "parameter_depth": 1
    }
}
  1. Deployed code (testzappa)[ec2-user@trialinstance testzappa]$ zappa deploy dev
  2. I get the same error Unable to import module 'handler': No module named werkzeug.wrappers
  3. Tried installing werkzeug
(testzappa)[ec2-user@trialinstance testzappa]$ pip install werkzeug but it already exists
Requirement already satisfied (use --upgrade to upgrade): werkzeug in ./lib/python2.7/dist-packages
(testzappa)[ec2-user@trialinstance testzappa]$ `

@collingreen
Copy link
Collaborator

I think this issue is actually this issue (#63). Can you rename your virtualenv to env (or probably anything that isnt the same name as your project) and see what happens?

@bjinwright
Copy link
Collaborator

I agree

@collingreen
Copy link
Collaborator

Update -- this also happens when flask is not installed in the virtualenv.

@ceefour
Copy link

ceefour commented Aug 31, 2017

@collingreen THANK YOU !

@monkut
Copy link

monkut commented Oct 13, 2017

Seeing this same issue while trying to use zappa with apistar (0.3.9).

(.venv) $ zappa tail
Calling tail for stage dev..
[XXX] Unable to import module 'handler': No module named 'werkzeug'
[XXX] Unable to import module 'handler': No module named 'werkzeug'
^C
(.venv) $ python -m pip install werkzeug
Requirement already satisfied: werkzeug in ./.venv/lib/python3.6/site-packages

I've rebuilt my venv several times with no effect...no sure what to try next.
(my virtrualenv (.venv) is not related or named anything that would conflict with my project..)

apistar==0.3.9
.
.
.
Werkzeug==0.12
whitenoise==3.3.1
wsgi-request-logger==0.4.6
zappa==0.44.3

@Sniedes722
Copy link

@Miserlou any advice for the

Unable to import module 'handler': No module named 'werkzeug'

error ?

Getting this same issue trying to deploy a django service. Flask & Werkzeug are installed in the venv, name is not conflicting.

@jjorissen52
Copy link

jjorissen52 commented Nov 7, 2017

@Sniedes722 Downgrading to 0.44.3 fixed the issue for me.

@Miserlou
Copy link
Owner

Miserlou commented Nov 7, 2017

Can anybody figure out where the regression was committed? Or what it is?

@Miserlou Miserlou reopened this Nov 7, 2017
@jwkvam
Copy link
Contributor

jwkvam commented Nov 17, 2017

This happens to me with slim_handler=True. I wonder if this is causing the issue uiri/toml#129

When the handler venv pip install tries to happen it tries to install toml==0.9.3 but it can't find it. Maybe we could ask toml to bump their version.

  Could not find a version that satisfies the requirement toml==0.9.3 (from versions: 0.6.0, 0.6.5, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.9.0, 0.9.1, 0.9.2, 0.9.3.1)
No matching distribution found for toml==0.9.3

I asked the maintainer to cut a new release in that issue. It seems weird stuff is happening because v0.9.3.1 on pypi still references itself as 0.9.3 in code. So if this is the problem we either wait for upstream or temporarily downgrade to 0.9.2 :/

@daviskeene
Copy link

Same issue, I'm trying to use slim_handler = True for my flask-ask skill but I get the same error message. Really hope they fix this soon!

@mcrowson
Copy link
Collaborator

mcrowson commented Dec 4, 2017

Would this be solved if Zappa didn't peg requirement versions?

@cotzanium
Copy link

cotzanium commented Dec 4, 2017

Im failing to update my zappa projects due to this " Could not find a version that satisfies the requirement toml==0.9.3 (from versions: 0.6.0, 0.6.5, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.9.0, 0.9.1, 0.9.2, 0.9.3.1) No matching distribution found for toml==0.9.3". Unfortunately it shows the error but still deploys it; breaking the previously working api. Is there a way for the deployment to fail if some requirements aren't met?

@technolingo
Copy link

The same issue with toml. Can this be manually solved?

@technolingo
Copy link

toml has released 0.9.4

@technolingo
Copy link

@Miserlou Is it caused by toml?

@ariemer
Copy link

ariemer commented Mar 13, 2018

Getting a similar error: Unable to import module 'handler': attempted relative import with no known parent package. (And earlier also: Unable to import module 'handler': No module named 'werkzeug' )

Windows 10, Python 3.6.2. Virtual environment name does not conflict. I have deleted and recreated several times, most recently with --no-site-packages. Spot checked some and found all are in .\venv\Lib\site-packages. handler.py of course is there too. Downgraded Zappa from 0.45.1 to 0.44.3. My project does include toml 0.9.4.

Zappa settings:

{
    "dev": {
        "app_function": "my_app.app",
        "aws_region": "us-west-2",
        "project_name": "my_app",
        "manage_roles": true,
        "runtime": "python3.6",
        "s3_bucket": "my_app-zappa-temp",
        "apigateway_enabled": false
    }
}

Any suggestions? I am stumped.

@ariemer
Copy link

ariemer commented Apr 24, 2018

Ultimately, I fixed this by doing a clean deployment with a new function name and keeping more default settings in zappa-settings, particularly apigateway_enabled.

@aphelionz
Copy link

aphelionz commented May 25, 2018

Getting this too, unfortunately, and am pretty stumped. Amazon Linux, Python 3.6. All my packages are inside of my virtualenv, which is named env. I had to downgrade to pip 9.0.3 because of a different error but can't seem to figure out why this one is happening...

@scoates
Copy link
Collaborator

scoates commented May 25, 2018

@aphelionz I had to hack my pips on Lambda. Not sure if that's what you mean by Amazon Linux, exactly, but just in case it's helpful:

# AWS broke pip. )-:
pip install --user --ignore-installed boto3 six virtualenv pip==9.0.3
export PYTHONPATH=$HOME/.local

# ...

$HOME/.local/bin/pip install --user --upgrade virtualenv

# now build the venv
rm -rf /tmp/venv
virtualenv /tmp/venv
. /tmp/venv/bin/activate
/tmp/venv/bin/pip install --ignore-installed pip==9.0.3

PYTHONPATH=`pwd`:$PYTHONPATH

/tmp/venv/bin/pip install --no-cache-dir --upgrade -r requirements.txt

@aphelionz
Copy link

aphelionz commented May 26, 2018

hmm same error :( the only thing i changed in your code was, in creating the virtualenv:

virtualenv /tmp/venv -p python3

@dins
Copy link

dins commented Jun 12, 2018

Could this be caused by #905 ?

At least for me it was fixed by copying contents of dist-packages to site-packages with:
cp -R ./.venv/lib/python3.6/dist-packages/* ./.venv/lib/python3.6/site-packages/

@sheats
Copy link

sheats commented Jun 22, 2018

I'm hitting this as well... if I unzip the handler_*.zip file the packaging deploys I'm noticing that werkzeug is not installed. This is all that's in there:

__init__.py
_sqlite3.so
django_zappa_app.py
handler.py
package_info.json
zappa
zappa-0.46.1.dist-info
zappa_settings.pyp

@sheats
Copy link

sheats commented Jun 22, 2018

I can reliably reproduce this issue using this repo: https://github.com/sheats/zappa_issue

make reproduce
make tail
[1529698001385] Unable to import module 'handler': No module named 'werkzeug'
[1529698009786] Unable to import module 'handler': No module named 'werkzeug'

@sheats
Copy link

sheats commented Jun 24, 2018

Turns out my problem was not activating the venv properly, this fixed it: https://github.com/sheats/zappa_issue/commit/331f69870320b31f6166731585ec7ae7dd8680fb

I thought the entrypoint.sh was activating the venv correctly but apparently not.

@xRichieGarcia
Copy link

Copying the contents of dist-packages to site-packages in my virtualenv as @dins suggested fixed the issue for me. I'm using Amazon Linux, and installed Werkzeug through Flask.

@Jbrown95
Copy link

Jbrown95 commented Jun 7, 2019

I just solved this issue for me a few minutes ago. I deleted my env using python3.6 and created a new one using 3.7. once in the new env, and after pip install zappa and pip install flask all is well.

@humphriesjm
Copy link

Make sure you run pip install zappa and pip install flask AFTER creating and activating your virtual environment (running virtualenv venv and source venv/bin/activate). This fixed the error for me.

@overcoil
Copy link

overcoil commented Apr 1, 2020

Make sure you run pip install zappa and pip install flask AFTER creating and activating your virtual environment (running virtualenv venv and source venv/bin/activate). This fixed the error for me.

I did a 'pip freeze >requirements.txt' and verified both zappa and flask were present in requirements.txt prior to 'zappa init'. Still having this problem.

@mattsahn
Copy link

mattsahn commented Apr 11, 2020

I just solved this issue for me a few minutes ago. I deleted my env using python3.6 and created a new one using 3.7. once in the new env, and after pip install zappa and pip install flask all is well.

This worked for me, too. Was using Cloud9 IDE, which had Python3.6, and had to install Python3.7 first, then create a new venv using Python3.7, reinstall everything, and everything works after that.

@isodrosotherm
Copy link

I did a 'pip freeze >requirements.txt' and verified both zappa and flask were present in requirements.txt prior to 'zappa init'. Still having this problem.

Same here. Windows 10, py 3.7, tried everything recommended here and then some, still no luck. if I run python after activating my env and run import werkzeug it imports fine, but then running zappa deploy dev it says it can't find werkzeug.

@yeaminhyperanna
Copy link

For me, I was creating separate 'run' steps in a CircleCI workflow/job for sourcing the virtualenv and running zappa update. But eventually bringing all shell commands under same 'run' step made the virtualenv persistent and the issue was solved.

@dygos2
Copy link

dygos2 commented Apr 4, 2023

Im my case, I had Zappa installed thru homebrew, but also installed inside the venv. After i uinstalled from homebrew and only used venv that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests