- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How to use remote python modules?
There are ways to import Python modules remotely. It is not recommended to do so though as it will slow down your app. You can use the knockout module to achieve this. To install knockout use:
$ pip install knockout
Now in order to import modules remotely, you can use knockout like:
>>> from knockout import urlimport >>> urlimport.register() Url importing enabled. Add urls to sys.path.
A valid url looks like this: http://example.com/path/to/repository/#packagename
This stuff is experimental, use at your own risk. Enjoy.
>>> import sys >>> sys.path.insert(0, 'http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.8/#BeautifulSoup') >>> import BeautifulSoup ... >>> BeautifulSoup <module 'BeautifulSoup' from 'http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.8/BeautifulSoup.py'>
If you are not able to install modules on a machine(due to not having enough permissions), you could use either virtualenv or save the module files in another directory and use the following code to allow Python to search for modules in the given module:
>>> import os, sys >>> file_path = 'AdditionalModules/' >>> sys.path.append(os.path.dirname(file_path)) >>> # Now python also searches AdditionalModules folder for importing modules as we have set it on the PYTHONPATH.
You can also use virtualenv to create an isolated local Python environment. The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded. This can also be used in our use case where we cannot install the package on the machine as we dont have the permissions. For more info on virtual env, read the docs: https://virtualenv.pypa.io/en/stable/
- Related Articles
- How to use Python modules over Paramiko (SSH)?
- How to use multiple modules with Python import Statement?
- How do we use easy_install to install Python modules?
- How to use pip to install python modules in easy way?
- Is it possible to use Python modules in Octave?
- How to check version of python modules?
- How to deploy python modules on Heroku?
- How to install Python modules in Cygwin?
- How do Python modules work?
- How to install python modules without root access?
- How to Use SFTP to Secure File Transfer with a Remote Server
- How to encapsulate Python modules in a single file?
- How to install libxml2 with python modules on Mac?
- How to install python modules and their dependencies easily?
- How to Install two python modules with same name?