Alibek Iganov
Alibek Iganov

Reputation: 13

cannot import name linkedin

I am here for the first time like a member and I'm new in python. I want to get a API string from linkedin using 'python-linkedin' package like this:

from linkedin import linkedin

API_KEY = 'my_key'
API_SECRET = 'my_secret'
RETURN_URL = 'http://127.0.0.1:8000'

authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
print authentication.authorization_url  # open this url on your browser
application = linkedin.LinkedInApplication(authentication)

I have got this error:

C:\Python27\python.exe C:/Users/alemcluster.ALEM/PycharmProjects/linkedinapi/linkedin.py
Traceback (most recent call last):
  File "C:/Users/alemcluster.ALEM/PycharmProjects/linkedinapi/linkedin.py", line 1, in <module>
from linkedin import linkedin
  File "C:\Users\alemcluster.ALEM\PycharmProjects\linkedinapi\linkedin.py", line 1, in <module>
from linkedin import linkedin
ImportError: cannot import name linkedin

Process finished with exit code 1

I tried to change linkedin to another variable, but does not help. I'm sorry if it is not properly posted. Prior to this, I only looked answers to questions.

Upvotes: 1

Views: 2631

Answers (2)

My3
My3

Reputation: 140

I faced the same issue. Initially I used pip3 install python-linkedin When I googled this issue, I saw that it works only for python2 but

I later tried pip3 install python3-linkedin

Now import statement works fine for me. Restart IDE and try... Hope that helps


If you installed linkedin, and/or python3-linkedin, you will want to first uninstall both packages and re-install python3-linkedin afterwards to ensure things work.

Upvotes: 1

Muhammad Hashim Shafiq
Muhammad Hashim Shafiq

Reputation: 653

I have got similar issue a while back. This is due to because your filename is also same as your library name and python interpreter first looks library in a working directory. And when interpreter checks working directory interpreter founds a same name as library name so interpreter start getting from it which is actually not library. That's why it is giving error.

Simple rename your file and you are good to go.

Hope It Works :)

Upvotes: 3

Related Questions