in <module>from duplicity.dup_main import mainModuleNotFoundError: No module named 'duplicity'.

Asked by Ignacy on 2020-04-17

Hey! It's my first time here and I'm not sure if I'm using the
system correctly.

TL;DR:
Duplicity didn't work after OS reinstall, probably due to a botched
python installation.
First an error showed during a backup, blocking it:
Attempt 1 failed. TypeError: can only concatenate str (not "bytes") to
strAttempt 1 failed. TypeError: can only concatenate str (not "bytes")
to str

After reinstalling from source there was another error. I reinstalled
from a snap and got the same error, which stopped even running
`duplicity --version`:
in <module>from duplicity.dup_main import mainModuleNotFoundError: No
module named 'duplicity'

After reinstalling latest version of pip and trying to install
duplicity from pip and being told that pip already installed it, I
copied files like this:
`cp -rp /usr/local/lib/python2.7/dist-packages/duplicity \
/usr/local/lib/python3.7/dist-packages/`
which solved the problem.

Thanks for your work on duplicity!

Long version:

Had issues using duplicity after a reinstall and moving from Ubuntu
Mate 18.04 to 19.10. (Used program called Aptik to assist with moving,
and it might have caused some chaos while reinstalling old
packages. It could've also been me using python/pip in an unskilled
way to install either b2 duplicity addon or some other software.)

First there was this error:
Attempt 1 failed. TypeError: can only concatenate str (not "bytes") to
strAttempt 1 failed. TypeError: can only concatenate str (not "bytes")
to str

duckduckgoing for answer led to this thread:
https://bugs.archlinux.org/task/65239

Here I got the idea to try running a more up-to-date version of
duplicity in hope that the bugs were fixed in the latest version.

I downloaded the source code and thanks to a really good documentation
managed to build and install the newer duplicity. However here came
another problem. When trying to run duplicity, even just duplicity
--version, there was another error:

in <module>from duplicity.dup_main import mainModuleNotFoundError: No
module named 'duplicity'

As I had no idea what import is or what module is, I started looking
in the source catalog and saw a catalog named 'snap'. Here I got the
idea to install duplicity as a snap package as it was something I'm
familiar with. When trying to run the snap package, got the same
error:
in <module>from duplicity.dup_main import mainModuleNotFoundError: No
module named 'duplicity'

After purging python pip that was installed by the system and
installing it from pip website, tried installing duplicity packages
trough pip. Pip reported, that Requirement already satisfied:
duplicity in /usr/local/lib/python2.7/dist-packages. And it was
there, but still didn't work. Then I educated myself as to what python
words 'import' and 'module' mean. That + reading the main duplicity
source file (where the problem occurred) made me wonder why
pip/duplicity installs into python 2.7 directory and not in python
3.7. I've copied the package preserving the modes with:
cp -rp /usr/local/lib/python2.7/dist-packages/duplicity \
/usr/local/lib/python3.7/dist-packages/

This fixed it and allowed running duplicity.

I'm not sure if the fault was with my python installation, but guessed
that snap package should've run even in spite of that as it probably
had it's own environment. Posting it here in case somebody else has
the same issues and needs an idea on how to fix them.

Question information

Language:
English Edit question
Status:
Solved
For:
Duplicity Edit question
Assignee:
No assignee Edit question
Solved by:
Ignacy
Solved:
2020-05-14
Last query:
2020-05-14
Last reply:
2020-04-18

When you installed the snap version, did you use 'sudo snap install duplicity --classic'? We had a problem with that a while back and it's been fixed.

ken@utest-19-04:~$ sudo snap install duplicity --classic
duplicity 0.8.12.1612 from Kenneth Loafman installed
ken@utest-19-04:~$ duplicity --version
duplicity 0.8.12

Same with 'sudo pip3 install duplicity'. It works. I need to look at pip/pip2. It should not have tried to install.

Ignacy (ignacy-sawa) said : #2

> When you installed the snap version, did you use 'sudo snap install
> duplicity --classic'? We had a problem with that a while back and it's
> been fixed.
That's how I installed the snap version. It didn't work, but most
likely python's fault, see below.

> Same with 'sudo pip3 install duplicity'. It works. I need to look at
> pip/pip2. It should not have tried to install.
When tried installing using 'sudo pip3 install duplicity', pip3
couldn't be found. It couldn't be installed either, because it was
already installed. Now I'm sure the issue was with my python
installation. I will take precautions when moving to Ubuntu 20.04, so
as not to drag with me old python files that most likely were the
source of this problem.