nanobox-io / nanobox-engine-python

Engine for running Python apps on Nanobox
https://nanobox.io
MIT License
12 stars 13 forks source link

Pip installs packages to different site-packages directory #17

Closed jason-riddle closed 8 years ago

jason-riddle commented 8 years ago
Note: This is without using virtualenv.

Installing a package with the following

[gonano@api /code]$ pip install falcon
<...>
Successfully installed Cython-0.23.4 falcon-0.3.0 python-mimeparse-0.1.4 six-1.10.0

and attempting to import the module leads to an error.

[gonano@api /code]$ python
Python 2.7.10 (default, Oct 26 2015, 17:54:35)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import falcon
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named falcon
>>>

Looking at sys.path, I noticed the following

[gonano@api /code]$ python -c 'import sys; print "\n".join(sys.path)'

<...>
/data/lib/python2.7/site-packages

which does not include the path where the package was actually installed (which is /code/env/lib/python2.7/site-packages).

[gonano@api /code]$ pip install falcon
<...>
Requirement already satisfied (use --upgrade to upgrade): falcon in /code/env/lib/python2.7/site-packages
<...>

and looking in the directory did indeed reveal the package.

[gonano@api /code]$ ls -al /code/env/lib/python2.7/site-packages
total 156
<...>
drwxr-xr-x  7 gonano gonano  4096 Dec 11 23:15 falcon
drwxr-xr-x  2 gonano gonano  4096 Dec 11 23:15 falcon-0.3.0-py2.7.egg-info
<...>
[gonano@api /code]$
tylerflint commented 8 years ago

Again, thanks for finding this! Having a knowledgable python developer to test the engine with real use cases is invaluable. We'll be sure to get these resolved as quickly as we can.

@notxarb Do you think this is related to the PATH issue you mentioned before? I wonder if /data/bin/python is still taking precedence over /code/env/bin/python?

@jason-riddle Could you provide the $PATH value that's set in there? echo $PATH

Thanks!

jason-riddle commented 8 years ago

Here is the $PATH.

[gonano@api /code]$ echo $PATH
/data/sbin:/data/bin:/opt/gonano/sbin:/opt/gonano/bin:/code/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
tylerflint commented 8 years ago

ah yep, that's the issue. Just to confirm, can modify your PATH and retry?

export PATH=/code/env/bin:$PATH

Thanks!

jason-riddle commented 8 years ago

Looks good! :+1:

jason-riddle commented 8 years ago

Thanks for the unbelievably quick responses, liking nanobox so far.

tylerflint commented 8 years ago

ok cool. I think we already have a fix in for this.

@glinton I'm pretty sure I saw a pull request from you in the last couple of weeks that would ensure that engine-provided PATHs would be before the default PATH. Does this sound right?

tylerflint commented 8 years ago

@jason-riddle awesome! Glad to hear it. We're still in our infancy but it's stabilizing quickly! We could really use your help to vet these fixes if you're willing.

glinton commented 8 years ago

@tylerflint That's correct we did have that fix in. I'm not a collaborator on the official engine so I couldn't publish. And i'm not sure if it got merged even or not

tylerflint commented 8 years ago

@glinton Let me fix the collaborator issue right now...

glinton commented 8 years ago

Also, my mistake, it actually has nothing to do with the engine, its nanobox-io/nanobox-docker-code#3, I'll merge that. then @jason-riddle if it doesn't work once dockerhub finishes building the image, you can just run nanobox update-images

tylerflint commented 8 years ago

@glinton It looks like nanobox-server will use the build image for the dev containers: https://github.com/nanobox-io/nanobox-server/blob/master/api/develop.go#L33

Does the change mentioned above need to be made for the build image as well?

glinton commented 8 years ago

@tylerflint I may be wrong, but I don't think so, the bashrc sets the custom path that is set here. Rather than using the build image, what would the up/downside be of launching 'dev' off of the current build container?

tylerflint commented 8 years ago

@glinton ok cool, looks like that should work then. As far as launching dev from the current build container, we tried that early on and realized they had different requirements for where and what to mount. It was different enough that it was cleaner and easier to just launch a new container from the build image and mount the /data dir from the build container into it.

@jason-riddle this issue should be resolved. To get the fix you can do the following:

nanobox update-images
nanobox dev --rebuild