Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install two python modules with same name

What's the best way to install two python modules with the same name? I currently depend on two different facebook libraries: pyfacebook and Facebook's new python-sdk. Both of these libraries install themselves as the module 'facebook'. I can think of a bunch of hacky solutions but before I go an hack away I was curious if there was a pythonic way of dealing with this situation.

I'm using virtualenv and pip.

(Yes, I will eventually deprecate one of them, but I had two different engineers working on two different problems and they didn't realize that they were using a different module until integration)

like image 447
guidoism Avatar asked Sep 09 '10 16:09

guidoism


People also ask

Can two different packages have modules with same name?

This is not possible with the pip. All of the packages on PyPI have unique names. Packages often require and depend on each other, and assume the name will not change. Even if you manage to put the code on Python path, when importing a module, python searches the paths in sys.

Can two classes have same name in Python?

yes, if you define a class with the same name as an already existing class, it will override the definition. BUT existing instances of the first class will still behave as usual.

Can we import multiple modules with single import statement?

Import multiple modulesYou can write multiple modules separated by commas after the import statement, but this is not recommended in PEP8. Imports should usually be on separate lines. If you use from to import functions, variables, classes, etc., as explained next, you can separate them with a comma.

Is there a way to install all Python modules at once using pip?

You can install from a requirement file: pip install -r requirements. txt . You can also list all installed packages and put it in a requirement file: pip freeze > requirement.


1 Answers

First, I'd suggest you guys go over what other libraries you're all using so you can get a concesus on how you're building your application.

To support this type of thing place each module within it's own folder, put in an __init__.py file, then you can do this:

import Folder1.facebook as pyfacebook
import Folder2.facebook as facebooksdk
like image 66
wheaties Avatar answered Sep 20 '22 00:09

wheaties