Python script with access to an SMB device

Hello @Mannshoch, you should read on the “virtual environment” topics on python. For example: Python Virtual Environments: A Primer – Real Python

In short you need to create a sandboxed environment where you will be able to download / install libraries (in your case pysmb.

Currently there is a bug on omnia which prevents you to do the virtualenv the “easy way”, I found a solution here: Python3 venv failed - #3 by sandor.balazsi

user@omnia:~$ python3 -m venv venv --without-pip
user@omnia:~$ source venv/bin/activate
(venv) user@omnia:~$ wget https://bootstrap.pypa.io/get-pip.py
--2023-11-14 10:20:23--  https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io... 151.101.0.175, 151.101.64.175, 151.101.128.175, ...
Connecting to bootstrap.pypa.io|151.101.0.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2632263 (2.5M) [text/x-python]
Saving to: ‘get-pip.py’

get-pip.py                                   100%[==============================================================================================>]   2.51M  --.-KB/s    in 0.1s

2023-11-14 10:20:24 (19.5 MB/s) - ‘get-pip.py’ saved [2632263/2632263]

(venv) user@omnia:~$ python3 get-pip.py
Collecting pip
  Downloading pip-23.3.1-py3-none-any.whl.metadata (3.5 kB)
Collecting setuptools
  Downloading setuptools-68.2.2-py3-none-any.whl.metadata (6.3 kB)
Collecting wheel
  Downloading wheel-0.41.3-py3-none-any.whl.metadata (2.2 kB)
Downloading pip-23.3.1-py3-none-any.whl (2.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 10.1 MB/s eta 0:00:00
Downloading setuptools-68.2.2-py3-none-any.whl (807 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 807.9/807.9 kB 13.5 MB/s eta 0:00:00
Downloading wheel-0.41.3-py3-none-any.whl (65 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.8/65.8 kB 5.5 MB/s eta 0:00:00
Installing collected packages: wheel, setuptools, pip
Successfully installed pip-23.3.1 setuptools-68.2.2 wheel-0.41.3
(venv) user@omnia:~$ pip3 install pysmb
Collecting pysmb
  Downloading pysmb-1.2.9.1.zip (1.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.4/1.4 MB 10.2 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting pyasn1 (from pysmb)
  Downloading pyasn1-0.5.0-py2.py3-none-any.whl (83 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 83.9/83.9 kB 6.9 MB/s eta 0:00:00
Collecting tqdm (from pysmb)
  Downloading tqdm-4.66.1-py3-none-any.whl.metadata (57 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.6/57.6 kB 5.2 MB/s eta 0:00:00
Downloading tqdm-4.66.1-py3-none-any.whl (78 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 kB 6.9 MB/s eta 0:00:00
Building wheels for collected packages: pysmb
  Building wheel for pysmb (setup.py) ... done
  Created wheel for pysmb: filename=pysmb-1.2.9.1-py3-none-any.whl size=84803 sha256=879139aca5711dac858303a017b56d6e4872220e536c575ce7fc4c3b5aaa6c22
  Stored in directory: /tmp/.cache/wheels/79/fb/86/032760e32fad1d9277f6ace4664fd1e946cb763711948ec2bb
Successfully built pysmb
Installing collected packages: tqdm, pyasn1, pysmb
Successfully installed pyasn1-0.5.0 pysmb-1.2.9.1 tqdm-4.66.1
(venv) user@omnia:~$ python3
Python 3.9.18 (main, Oct 09 2023, 18:02:40)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from smb.SMBConnection import SMBConnection
>>>
(venv) user@omnia:~$

When you work on your script you always need to do the “source venv/bin/activate” (venv == your name of virtual environment).

To turn off virtual environment just type “deactivate”

1 Like