synology NAS, pip issue, python libraries - python

I recently acquired a NAS and trying to run a python script. Issue is that I cannot run the python script as a normal user (python script.py). Python is only running if I run as a sudo user (e.g., sudo python script.py)
When I run as a normal user, it does not detect the libraries such as pandas. But I do not want to run as a sudo because sudo would required a password.
I think the issue comes from the pip installation.
Do you know what could be the issue?
Greatly appreciate
In the terminal, when I run "pip list" as a normal user, it states 'ModuleNotFoundError: No module named 'pip._internal'
`
user#NAS:~$ pip list
Traceback (most recent call last):
File "/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'
but when I run as a sudo:
user#NAS:~$ sudo pip list
Password:
Package Version
certifi 2022.6.15
charset-normalizer 2.1.1
idna 3.3
numpy 1.23.2
pandas 1.5.1
pip 22.3.1
pyasn1 0.4.5
pysmb 1.2.2
python-dateutil 2.8.2
pytz 2022.2.1
requests 2.28.1
setuptools 56.0.0
six 1.16.0
thread6 0.2.0
urllib3 1.26.12
wheel 0.38.4

Related

venv cannot find python library even though I definitely have it installed

Im runnig a windows 10 machine, and im getting started on playing with virtual enviorments. I want to run a small fastapi application
I created a venv like this:
python -m venv venv
I then activated the venv, and installed my two dependencies:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> pip install fastapi
and
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> pip install unicorn
Which seemed to work fine, running pip list also seems to indicate that i have what I need:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> pip list
Package Version
----------------- ---------
beautifulsoup4 4.9.3
certifi 2020.6.20
cffi 1.14.3
chardet 3.0.4
crypto 1.4.1
cryptography 3.1.1
cycler 0.10.0
fastapi 0.63.0
idna 2.10
myModule 1.0.0
Naked 0.1.31
pip 21.0.1
pycparser 2.20
pycrypto 2.6.1
pydantic 1.8.1
PyYAML 5.3.1
requests 2.24.0
setuptools 49.2.1
shellescape 3.8.1
six 1.15.0
soupsieve 2.0.1
starlette 0.13.6
typing-extensions 3.7.4.3
unicorn 1.0.2
urllib3 1.25.10
wheel 0.35.1
But when I run my program it fails with the inmport of the fastapI:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> python .\main.py
Traceback (most recent call last):
File "C:\Users\Ask\python_Projects\garse_dockerAPI\app\main.py", line 3, in <module>
from fastapi import FastAPI
Also, running python my terminal doesnt wanna do it either:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'fastapi'
What's going on? why do i not have the dependencies i need?
EDIT:
In order to find the installation on my machine, I ran 'where python' in my normal terminal:
C:\Users\Ask>where python
C:\Users\Ask\AppData\Local\Programs\Python\Python39\python.exe
C:\Users\Ask\AppData\Local\Microsoft\WindowsApps\python.exe
Which give sme two different paths. I dont really know what to do with this information?
running where pip:
C:\Users\Ask>where pip
C:\Users\Ask\AppData\Local\Programs\Python\Python39\Scripts\pip.exe
When I run it in my venv, the commands output nothing at all:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> where pip
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> where python
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app>
I definitely recommend using python3 -m pip instead of pure pip. It might save you some headache. The reason: when I used pip to install new packages in a venv virtual environment, they ended up in my OS environment! But just using python3 -m pip did the trick.
To make sure that the packages are called from your virtual environment, you can use python3 -m PACKAGE_NAME instead of PACKAGE_NAME. For example, flower didn't work in my virtual environment, but python3 -m flower works with no problem.
You can directly ask python where it is executed from! Try this:
>>> import sys
>>> print(sys.executable)
/PATH/TO/VENV/bin/python
>>> print(sys.version)
'3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0]'

ModuleNotFoundError: No module named 'keyboard, tried pip3 install, tried -pip list it is there

Some extra info:
I am on Windows 10, using latest Python version, using latest pip version, using Pycharm as my IDE. I am making a keylogger program for a project and I cannot seem to get keyboard module working.
Also:
C:\Users\Hp>pip --version
pip 20.2.2 from c:\users\hp\appdata\local\programs\python\python38-32\lib\site-packages\pip (python 3.8)
C:\Users\Hp>pip install keyboard
Requirement already satisfied: keyboard in c:\users\hp\appdata\local\programs\python\python38-32\lib\site-packages (0.13.5)
C:\Users\Hp>pip list
Package Version
altgraph 0.17
future 0.18.2
keyboard 0.13.5
pefile 2019.4.18
pip 20.2.2
PyInstaller 3.6
pywin32-ctypes 0.2.0
setuptools 41.2.0
The error message in PyCharm: C:\Users\Hp\Desktop\keylogger\venv\Scripts\python.exe C:/Users/Hp/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/keylog.py
Traceback (most recent call last):
File "C:/Users/Hp/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/keylog.py", line 2, in
import keyboard
ModuleNotFoundError: No module named 'keyboard'
Activate your virtual-environment
.\env\Scripts\activate
or
C:\Users\Hp\Desktop\keylogger\venv\Scripts\activate
Now install keyboard
pip install keyboard
#yedpodtrzitko already answered, I just want to make it clearer with solution-steps.

Uninstalled wrapt module: Python not working

I was having difficulty installing a package because of a ModuleNotFoundError for wrapt and so I removed and tried to reinstall wrapt.
I ran the uninstall once, and wrapt was removed from one location. I tried to install, but the requirement was already satisfied, so I uninstalled wrapt again. See the three commands below:
Found existing installation: wrapt 1.12.1
Uninstalling wrapt-1.12.1:
Would remove:
c:\users\me\appdata\roaming\python\python38\site-packages\wrapt-1.12.1-py3.8.egg-info
c:\users\me\appdata\roaming\python\python38\site-packages\wrapt\*
Proceed (y/n)? y
Successfully uninstalled wrapt-1.12.1
PS C:\Users\me> pip install wrapt
Requirement already satisfied: wrapt in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (1.12.1)
PS C:\Users\me> pip uninstall wrapt
Found existing installation: wrapt 1.12.1
Uninstalling wrapt-1.12.1:
Would remove:
c:\users\me\appdata\local\programs\python\python38\lib\site-packages\wrapt-1.12.1.dist-info\*
c:\users\me\appdata\local\programs\python\python38\lib\site-packages\wrapt\*
Proceed (y/n)? y
Successfully uninstalled wrapt-1.12.1
I thought I was all ready to start with a clean slate, but no such luck. Now I receive the following error whenever I try to run python or pip.
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "c:\users\me\appdata\local\programs\python\python38\lib\site.py", line 580, in <module>
main()
File "c:\users\me\appdata\local\programs\python\python38\lib\site.py", line 575, in main
execusercustomize()
File "c:\users\me\appdata\local\programs\python\python38\lib\site-packages\certifi_win32\bootstrap.py", line 45, in _execusercustomize
_register_bootstrap_functions()
File "c:\users\me\appdata\local\programs\python\python38\lib\site-packages\certifi_win32\bootstrap.py", line 25, in _register_bootstrap_functions
from . import wrapt_certifi
File "c:\users\me\appdata\local\programs\python\python38\lib\site-packages\certifi_win32\wrapt_certifi.py", line 3, in <module>
import wrapt
ModuleNotFoundError: No module named 'wrapt'
I've tried finding installation for wrapt that does not use pip, but I haven't been successful. I also attempted upgrading Python from 3.8.1 to 3.8.3, which resulted in the same ModuleNotFoundError. Uninstalling Python and installing again yielded the same result. I currently cannot use my manually installed Python or pip at all.
What would you recommend?
The solution was to use a second installation of Python (Anaconda) to fix my broken Python. My Anaconda Python maintains a separate set of installed packages, so it was still working. I opened an Anaconda prompt and ran (reference):
pip install --target="c:\users\me\appdata\local\programs\python\python38\lib\site-packages" wrapt
This reinstalled wrapt in the correct site-packages folder. My original Python is now working.
Lesson learned: be careful with pip uninstall

ModuleNotFoundError when using venv

I have just installed Python 3.8 on a Mac Catalina machine.
I have created a new virtual env using PyCharm and installed the slackclient package using PyCharm's preferences.
However, whichever way I try to run the app, I get the ModuleNotFoundError: No module named 'slackclient' error.
I have verified that it is installed in the OS terminal (zsh):
(venv) *** pip list
Package Version
------------- -------
aiohttp 3.6.2
async-timeout 3.0.1
attrs 19.3.0
chardet 3.0.4
idna 2.9
multidict 4.7.5
pip 20.0.2
setuptools 46.1.3
slackclient 2.5.0
yarl 1.4.2
(venv) *** python studiobot.py
Traceback (most recent call last):
File "studiobot.py", line 4, in <module>
from slackclient import SlackClient
ModuleNotFoundError: No module named 'slackclient'
What am I doing wrong?
Thanks in advance!
You should be using something like
from slack import WebClient
https://github.com/slackapi/python-slackclient#sending-a-message-to-slack

Error when upgrading Spyder to 4.0.1: ModuleNotFoundError: No module named 'IPython.core.inputtransformer2'

I recently upgraded to Spyder 4.0.1 through Anaconda via conda update spyder. Now, when I try to boot up Spyder via Anaconda Navigator, the program automatically crashes with the following dump:
Traceback (most recent call last):
File "/Users/ed/anaconda/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 3718, in main
mainwindow = run_spyder(app, options, args)
File "/Users/ed/anaconda/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 3559, in run_spyder
main.setup()
File "/Users/ed/anaconda/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 1010, in setup
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
File "/Users/ed/anaconda/lib/python3.6/site-packages/spyder/plugins/ipythonconsole/plugin.py", line 52, in
from spyder.plugins.ipythonconsole.widgets import ClientWidget
File "/Users/ed/anaconda/lib/python3.6/site-packages/spyder/plugins/ipythonconsole/widgets/__init__.py", line 16, in
from .debugging import DebuggingWidget
File "/Users/ed/anaconda/lib/python3.6/site-packages/spyder/plugins/ipythonconsole/widgets/debugging.py", line 22, in
from IPython.core.inputtransformer2 import TransformerManager
ModuleNotFoundError: No module named 'IPython.core.inputtransformer2'
I couldn't find anybody with a similar error. I updated IPython, as someone suggested, but it did not resolve the problem. Any ideas?
... since none of this worked for me, here how I solved it:
check what IPython version you have via conda list
in my case i got a rather old version 5.8.0 instead of the most recent one
(at the time of writing 7.19.0... check available versions via conda search ipython)
since conda update ipython did not provide the most recent version, i decided
to manually run the command that installs the most recent version
(for me this was conda install -c conda-forge ipython=7.19.0)
that's it...
I had the same problem. Upgrading IPython via the following command line helped resolve the situation.
sudo conda update IPython -n xxx
where xxx is the name of the environment I was trying to run Spyder in.
I had this very same issue on Spyder 4.1.4. Turns out that not all the required packages were installed correctly when I installed Spyder.
I used the following in python to test IPython:
import IPython
print(IPython.__version__)
Turned out that I had 6.4.0 so I ran the following from the terminal:
!pip install --upgrade IPython
IPython 7.16.1 was installed with prompt_toolkit-3.0.5. I also got the following errors:
ERROR: spyder 4.1.4 requires pyqt5<5.13; python_version >= "3", which is not installed.
ERROR: spyder 4.1.4 requires pyqtwebengine<5.13; python_version >= "3", which is not installed.
ERROR: jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you'll have prompt-toolkit 3.0.5 which is incompatible.
ERROR: spyder 4.1.4 has requirement jedi==0.17.1, but you'll have jedi 0.12.1 which is incompatible.
ERROR: spyder 4.1.4 has requirement parso==0.7.0, but you'll have parso 0.3.0 which is incompatible.
ERROR: spyder 4.1.4 has requirement qtconsole>=4.6.0, but you'll have qtconsole 4.3.1 which is incompatible.
ERROR: spyder-kernels 1.9.2 has requirement ipykernel>=5.1.3; python_version > "2", but you'll have ipykernel 4.8.2 which is incompatible.
ERROR: spyder-kernels 1.9.2 has requirement jupyter-client>=5.3.4, but you'll have jupyter-client 5.2.3 which is incompatible.
Installing the correct versions of the above packages in pip resolved my problem.
Update to python 3.7. I had the same problem. That solved it.
conda install python=3.7 anaconda=custom
I experienced the same problem. Just do conda update IPython. All good then!

Categories