Forums

Accessing module in Web2py

Another minor question that I can't figure out.

I've used pip-2.7 install --user soundcloud to install the soundcloud module for Python 2.7 in Pythonanywhere.

In my Web2py App in Pythonanywhere, I get an error message when using import soundcloud, stating that the soundcloud module does not exist. Is it not possible to for Web2py to access a module installed on Pythonanywhere (that did not come pre-packaged)?

I suspect the problem is that web2py is running in 2.6, while your Soundcloud library is 2.7.

But I could be wrong...

I actually installed the soundcloud module in 2.6 as well (didn't know I needed to add the -2.7 originally for pip install).

Just to confirm: if you go to a Python 2.6 console, and type 'import soundcloud', then that works

Yeah there's no problem importing soundcloud in the 2.6 console.

Make sure the soundcloud module file is installed in web2py/site-packages rather than web2py/applications/yourapp/modules

Hey marladarla7. Did pyhead's suggestion help?

the module files installed by pip in pythonanywhere are installed in the .local folder for pythonanywhere, not the web2py/site-packages directory. I wanted to avoid having to move the module files into the web2py folder, instead accessing the module as suggested here:

http://stackoverflow.com/questions/11476886/accessing-module-installed-on-pythonanywhere-in-web2py

However, if I was to move the module files into the web2py folder, is there a way to upload multiple files at once (like an entire folder), as opposed to uploading files individually?

if you're familiar with the shell you can copy a folder with

cp -R source destination

to keep the files in .local you could also link to them like

ln -s .local/soundcloud web2py/site-packages/soundcloud

I used the cp command to copy the files from the local python install to the web2py/applications/yourapp/modules folder. I'm a windows user so I was unfamiliar with the shell commands (such as copying files). Is there a reason specific to Pythonanywhere that you suggested to move the files into the web2py/site-packages as opposed to the app/modules folder?

I opted to not use the symlink option so I could better isolate the app environment, as I may change the contents of .local.

Thanks again for the help!

I once had a similar problem, someone suggested to try puting the module in site-packages and it worked. I can't find any reference of other occurances of this happenng.

The manual says you could actually put them in either web2py/site-packages or web2py/applications/yourapp/modules and it should work.

http://web2py.com/books/default/chapter/29/4?search=site-packages

Let us know if you come across anything that would explain this, or maybe try moving soundcloud to the modules folder to see if it works there too.

It's working fine in the app/modules folder right now, I'll update if I run into any problems.