K
K
Kot Kotov2020-05-15 19:53:11
linux
Kot Kotov, 2020-05-15 19:53:11

How to fix py3 error?

there is a program, I immediately say I copy-pasted it, for the purpose of familiarization, here it is:

from vk_api.longpoll import VkLongPoll, VkEventType
import vk_api
from datetime import datetime

login, password = "мой логин", "пароль"
vk_session = vk_api.VkApi(login=login, password=password, app_id=2685278)
vk_session.auth(token_only=True)

token = "токен"
vk_session = vk_api.VkApi(token=token)

session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
#While True здесь оказался не нужен. Его функцию выполняет for event in longpoll.listen(): Спасибо подписчику за это уточнение.

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        print('Сообщение пришло в: ' + str(datetime.strftime(datetime.now(), "%H:%M:%S")))
        print('Текст сообщения: ' + str(event.text))


when I run it from the console, I get this:
from: can't read /var/mail/vk_api.longpoll
import-im6.q16: not authorized `vk_api' @ error/constitute.c/WriteImage/1037.
from: can't read /var/mail/datetime
./vkBot.py: 5: ./vkBot.py: login,: not found
./vkBot.py: 6: ./vkBot.py: Syntax error: "(" unexpected

changed:
I realized that I do not have this lib installed and I need to install it, but when installing pip, it gives errors
if I run it without root
The directory '/home/kokos/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/kokos/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting vk_api
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 342, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 281, in populate_link
    self.link = self._wheel_cache.cached_wheel(self.link, self.name)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 68, in cached_wheel
    self._cache_dir, link, self._format_control, package_name)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 129, in cached_wheel
    wheel_names = os.listdir(root)
PermissionError: [Errno 13] Отказано в доступе: '/home/kokos/.cache/pip/wheels/39/bb/05/c3d370a1097f993c1089e0c6265f7cb782b4a583110f747805'

And this one is from root
Requirement already satisfied: vk_api in /home/kokos/.local/lib/python3.6/site-packages
Requirement already satisfied: requests in /home/kokos/.local/lib/python3.6/site-packages (from vk_api)
Requirement already satisfied: six in /home/kokos/.local/lib/python3.6/site-packages (from vk_api)
Requirement already satisfied: idna<3,>=2.5 in /home/kokos/.local/lib/python3.6/site-packages (from requests->vk_api)
Requirement already satisfied: certifi>=2017.4.17 in /home/kokos/.local/lib/python3.6/site-packages (from requests->vk_api)
Requirement already satisfied: chardet<4,>=3.0.2 in /home/kokos/.local/lib/python3.6/site-packages (from requests->vk_api)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/kokos/.local/lib/python3.6/site-packages (from requests->vk_api)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan2033, 2020-05-15
@Bogdan2033

Syntax error: "(" unexpected - check this place, apparently there is no parenthesis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question