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

Cannot import in pycharm 2017.2 #1148

Closed
Chez opened this issue Oct 18, 2017 · 8 comments
Closed

Cannot import in pycharm 2017.2 #1148

Chez opened this issue Oct 18, 2017 · 8 comments

Comments

@Chez
Copy link

Chez commented Oct 18, 2017

I am using python2.7.14 and have a virtualenv setup and have installed psutil via Pycharm to the virtualenv. Importing in the console or from the terminal python is fine, nut it just will not import in Pycharm, so you have any ideas?

@giampaolo
Copy link
Owner

I am not a PyCharm user but I doubt anyone can have the slightest idea since you basically provided zero useful information.

@sethmlarson
Copy link

sethmlarson commented Oct 18, 2017

If you can give me a list of commands and steps to reproduce your environment I would give this a shot.

@Chez
Copy link
Author

Chez commented Oct 19, 2017

Yes, sorry, it had been a long day. Anyway, If you setup two simple projects in Pycharm, both using the same 2.7.14 virtualenv with psutils installed: Thus,

Standard Vanilla Python Project:

main.py contains

import psutil

def x():
    print "hello world"

if __name__ == "__main__":
    x()

Google App Engine Project -
main.py contains

import webapp2
import psutil

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

The import in the vanilla python project works fine, but the import in the GAE app returns the traceback:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/chez 1/google-app-engine-projects/untitled/main.py", line 18, in <module>
    import psutil
ImportError: No module named psutil

@sethmlarson
Copy link

Does Google webapp mess with imports? It looks like it's doing something with __import__ there.

@Chez
Copy link
Author

Chez commented Oct 19, 2017

I think it does, yes. It has a list of third party packages that you can specify in the app.yaml, unfortunately psutil is not on it. I have no idea why.

I came about this error via attempting to use Google cloud pubsub. The pubsub import works but that package calls types.py which imports psutil and fails everytime. There is an issue out there I found... googleapis/google-cloud-python#3892

@Chez
Copy link
Author

Chez commented Oct 20, 2017

I tried as per Google's recomendations for installing third party software "Using third-party libraries" online document. But this raises another exception:

"Using third-party libraries" online document.

File "/Users/chez 1/google-app-engine-projects/pitpit-gae/supplier/api/v1/handlers.py", line 9, in <module>
  import psutil
File "/Users/chez 1/google-app-engine-projects/pitpit-gae/external/psutil/__init__.py", line 149, in <module>
  from . import _psosx as _psplatform
File "/Users/chez 1/google-app-engine-projects/pitpit-gae/external/psutil/_psosx.py", line 16, in <module>
  from . import _psutil_osx as cext
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 965, in load_module
  raise ImportError('No module named %s' % fullname)

@hugovk
Copy link
Contributor

hugovk commented Oct 25, 2017

By the way, PyCharm is available for free for open-source projects: https://www.jetbrains.com/buy/opensource/

@giampaolo
Copy link
Owner

Closing this out as it seems related to PyCharm.

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

4 participants