I have encountered a lot of problems trying to get modules work in the hosting, so i have thought it would be nice to share my experience and solutions.
-I need to use a module and cant be imported
First of all you have to have python installed in another computer. I use bash for windows 10, so i will put the commands that works on linux.I will be using python version 2.7.
After that, you have 2 options to get the module:
--You can install it via
|pip install <module>|
--You can compile it from source, which you can usually find in https://pypi.python.org. After you donwloaded it, extract it, cd into the folder and run
|python setup.py build|
Then a build folder will be created and enter the folders inside until you find one with the same name as the module, zip it and upload it.
Now that you have a zipped version of your module in the hosting, you have to create folder for the modules. I personally created /home/<username>/public_html/libs but it can be anything that you can access. After creating the folder you have to unzip the module inside.
Afterwards, you have to include the following line of code before all the imports:
After this line you can put the necessary imports. Here is an example of one full code:
# -*- coding: utf-8 -*-
browser = mechanize.Browser()
This is just a sample of using a module called mechanize to scrape a webpage.
It's important that any print that you make is in html format, if not a 500 error will show
0 blog comments below