A
A
artjerom2016-06-15 16:00:59
Python
artjerom, 2016-06-15 16:00:59

Why doesn't python see the module?

python doesn't see vk module, already tried many solutions and nothing helps. At the same time, modules like random work fine.

import vk

vkapi = vk.API('id_app', 'login', 'pass')
vkapi.access_token='tokken'
vkapi.wall.post(message="Hello, world")

oc Ubuntu
In the console outputs:
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import vk
ImportError: No module named 'vk'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Biryukov-Romanov, 2016-06-15
@artjerom

~/vk-test$ virtualenv env
New python executable in env/bin/python
Installing setuptools, pip...done.
~/vk-test$ . env/bin/activate
(env)~/vk-test$ pip install vk
Downloading/unpacking vk
  Downloading vk-2.0.2.tar.gz
  Running setup.py (path:/home/urtow/vk-test/env/build/vk/setup.py) egg_info for package vk
    
Downloading/unpacking requests>=2.8,<3.0 (from vk)
  Downloading requests-2.10.0-py2.py3-none-any.whl (506kB): 506kB downloaded
Installing collected packages: vk, requests
  Running setup.py install for vk
    
Successfully installed vk requests
Cleaning up...
(env)~/vk-test$ ipython 
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
...

In [1]: import vk

So, based on everything above - you have everything right with the code.
There can be three problems:
1) An error during the installation process.
2) You installed the module in virtualenv, and you run it outside of it.
3) By default, the vk module in ubuntu 14.04 is set for python2. If you try to run the script in python3, you will get this error:
ipython3
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
....

In [1]: import vk
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-d1455673e4d4> in <module>()
----> 1 import vk

ImportError: No module named 'vk'

According to https://pypi.python.org/pypi/vk the module supports python version 3.
So you just need to install it under the desired version.
~/vk-test$ virtualenv -p python3 env
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in env/bin/python3
Also creating executable in env/bin/python
Installing setuptools, pip...done.
[email protected]:~/vk-test$ . env/bin/activate
(env)~/vk-test$ python
Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
(env)~/vk-test$ pip install vk
Downloading/unpacking vk
  Downloading vk-2.0.2.tar.gz
  Running setup.py (path:/home/urtow/vk-test/env/build/vk/setup.py) egg_info for package vk
    
Downloading/unpacking requests>=2.8,<3.0 (from vk)
  Downloading requests-2.10.0-py2.py3-none-any.whl (506kB): 506kB downloaded
Installing collected packages: vk, requests
  Running setup.py install for vk
    
Successfully installed vk requests
Cleaning up...
(env)~/vk-test$ ipython3
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
...

In [1]: import vk

In [2]:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question