How to upgrade Pymedphys

I was using Pymedphys code to do some gamma analysis. Previously I have installed an old version (0.11.0) last year. I saw recently it’s been upgraded to version 0.34.0. Just wondering has there been much change in the gamma analysis function? Is there an easy way to upgrade to the newest version? I’m using hospital computer so it’s got admin/firewall issues. I had some trouble while I was installing the previous version as well. The “pip” install was not working because I don’t have admin rights. At the moment I’ve got anoconda3 installed on my computer. I would appreciate it if you could give me some advice on how to upgrade to the newest version, and maybe keep updated automatically?

Hi @nancyyu,

Welcome to the PyMedPhys Discourse community :slight_smile: :tada: :slight_smile:

Given everyone’s Python environment is a bit different, potentially with all sorts of weird things going on, one way to guarantee that the install location is in a place that you have user rights to is to create a virtual environment in your home directory.

If you open up a command prompt (cmd.exe) and run the following:

python -m venv %USERPROFILE%\.pymedphys-venv
%USERPROFILE%\.pymedphys-venv\Scripts\activate
pip install pymedphys[user]

What should be left is a standalone Python environment not interacting with anything else on your system. Then, if you ever want to use this standalone PyMedPhys you just need to run:

%USERPROFILE%\.pymedphys-venv\Scripts\activate

And that environment you created will become available.

Do you happen to also use Jupyter Lab/Notebooks? How do you normally interact with PyMedPhys Gamma?

Cheers,
Simon

To find out what’s changed since version 0.11.0 (that was a while ago :slight_smile:) have a look at:

By doing a Ctrl + F for “gamma” within the release notes I found the following link under version 0.14.1:

That was flagged as a bug fix.

Cheers,
Simon

In the future I do plan to release an all in one PyMedPhys.exe. My hope is that automated updating can be enabled for that. That is a while away though… (possibly more than 12 months). However if you install PyMedPhys as detailed above and run:

%USERPROFILE%\.pymedphys-venv\Scripts\activate
pip install --upgrade pymedphys[user]

That should allow you to upgrade your installation.

Cheers,
Simon

Hi Simon,

Thank you so much for your reply! I tried to run your command to set up the environment. The first two lines work but when I tried to do pip install, it comes up with the following error. I’m not sure if it’s because I’ve got the previous version installed or something else. Any advice would be appreciated! Thanks!

(.pymedphys-venv) C:\Users\YuLit>pip install pymedphys[user]
Collecting pymedphys[user]
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000294F03EDE48>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000294F03E96C8>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000294F03E74C8>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000294F03E7F08>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000294F03E7108>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
  Could not find a version that satisfies the requirement pymedphys[user] (from versions: )
No matching distribution found for pymedphys[user]

I’m not using Jupyter. At the moment i’m using Anaconda3 spyder to interact with Pymedphys.

I’m quite sure it’s not to do with something else that’s installed. Instead, from a bit of “Google Foo”, I suspect it may be because at work your internet connection is behind a corporate proxy.

There is some advice over at the following stackoverflow answer:

Is there someone else in your centre who has installed something with pip before? I’d be keen to know what works for you, I’m sure others who might read this in the future might also be quite interested.

Cheers,
Simon

Also, if you do get the pip install to work, you’ll need to configure Spyder to use the virtual environment that we’ve just made over at %USERPROFILE%\.pymedphys-venv (by the way, that path is the same as saying C:\Users\YuLit\.pymedphys-venv on your PC).

The below is a guide explaining how to configure Spyder for a virtual environment:

Cheers :slightly_smiling_face:,
Simon

Hi Simon,

I had a look at my internet settings. It seems I have direct access with no proxy server. I tried your upgrade command without configuring the virtual environment and got the following. It seems it’s already updated? (sorry about the long screenshot, just wanted to show you all information)

C:\Users\YuLit>pip install --upgrade pymedphys[user]
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000163B6BB6FC8>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000163B6BB6208>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000163B6BB5688>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000163B6BC7608>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000163B6BC7388>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymedphys/
Requirement already up-to-date: pymedphys[user] in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (0.11.0)
  WARNING: pymedphys 0.11.0 does not provide the extra 'user'
Requirement already satisfied, skipping upgrade: pymedphys-pinnacle<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-analysis<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-gamma<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-labs<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-base<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-utilities<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-electronfactors<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-databases<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-logfiles<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-xlwings<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-fileformats<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-coordsandscales<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-dicom<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pymedphys-mudensity<0.12.0,>=0.11.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys[user]) (0.11.0)
Requirement already satisfied, skipping upgrade: pydicom in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-pinnacle<0.12.0,>=0.11.0->pymedphys[user]) (1.3.0)
Requirement already satisfied, skipping upgrade: PyYAML in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-pinnacle<0.12.0,>=0.11.0->pymedphys[user]) (5.1.2)
Requirement already satisfied, skipping upgrade: numpy>=1.12 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-pinnacle<0.12.0,>=0.11.0->pymedphys[user]) (1.16.5)
Requirement already satisfied, skipping upgrade: matplotlib in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-analysis<0.12.0,>=0.11.0->pymedphys[user]) (3.1.1)
Requirement already satisfied, skipping upgrade: scipy in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-analysis<0.12.0,>=0.11.0->pymedphys[user]) (1.3.1)
Requirement already satisfied, skipping upgrade: scikit-image in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (0.15.0)
Requirement already satisfied, skipping upgrade: Pillow in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (6.2.0)
Requirement already satisfied, skipping upgrade: tqdm in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (4.36.1)
Requirement already satisfied, skipping upgrade: imageio in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (2.6.0)
Requirement already satisfied, skipping upgrade: shapely in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-electronfactors<0.12.0,>=0.11.0->pymedphys[user]) (1.6.4.post2)
Requirement already satisfied, skipping upgrade: pymssql in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (2.1.4)
Requirement already satisfied, skipping upgrade: pandas in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (0.25.1)
Requirement already satisfied, skipping upgrade: attrs in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (19.2.0)
Requirement already satisfied, skipping upgrade: keyring in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (18.0.0)
Requirement already satisfied, skipping upgrade: python-dateutil in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-logfiles<0.12.0,>=0.11.0->pymedphys[user]) (2.8.0)
Requirement already satisfied, skipping upgrade: xlwings; platform_system != "Linux" in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-xlwings<0.12.0,>=0.11.0->pymedphys[user]) (0.15.10)
Requirement already satisfied, skipping upgrade: packaging in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pymedphys-dicom<0.12.0,>=0.11.0->pymedphys[user]) (19.2)
Requirement already satisfied, skipping upgrade: cycler>=0.10 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from matplotlib->pymedphys-analysis<0.12.0,>=0.11.0->pymedphys[user]) (0.10.0)
Requirement already satisfied, skipping upgrade: kiwisolver>=1.0.1 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from matplotlib->pymedphys-analysis<0.12.0,>=0.11.0->pymedphys[user]) (1.1.0)
Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from matplotlib->pymedphys-analysis<0.12.0,>=0.11.0->pymedphys[user]) (2.4.2)
Requirement already satisfied, skipping upgrade: PyWavelets>=0.4.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from scikit-image->pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (1.0.3)
Requirement already satisfied, skipping upgrade: networkx>=2.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from scikit-image->pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (2.3)
Requirement already satisfied, skipping upgrade: pytz>=2017.2 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from pandas->pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (2019.3)
Requirement already satisfied, skipping upgrade: pywin32; sys_platform == "win32" in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from keyring->pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (223)
Requirement already satisfied, skipping upgrade: entrypoints in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from keyring->pymedphys-databases<0.12.0,>=0.11.0->pymedphys[user]) (0.3)
Requirement already satisfied, skipping upgrade: six>=1.5 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from python-dateutil->pymedphys-logfiles<0.12.0,>=0.11.0->pymedphys[user]) (1.12.0)
Requirement already satisfied, skipping upgrade: comtypes in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from xlwings; platform_system != "Linux"->pymedphys-xlwings<0.12.0,>=0.11.0->pymedphys[user]) (1.1.7)
Requirement already satisfied, skipping upgrade: setuptools in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from kiwisolver>=1.0.1->matplotlib->pymedphys-analysis<0.12.0,>=0.11.0->pymedphys[user]) (41.4.0)
Requirement already satisfied, skipping upgrade: decorator>=4.3.0 in c:\users\yulit\appdata\local\continuum\anaconda3\lib\site-packages (from networkx>=2.0->scikit-image->pymedphys-labs<0.12.0,>=0.11.0->pymedphys[user]) (4.4.0)

All good about the long screenshot :slightly_smiling_face:, I changed the formatting a little so that it’s easier to read though. Copying it all in is quite helpful to get an idea of what’s going on :slightly_smiling_face:, it also helps others when they Google search the error message.

It looks like, what’s going on there, is it is trying to connect to PyPI and failing, and then since it failed it is falling back to your already installed PyMedPhys. Given it can’t connect to PyPI, it doesn’t know that v0.11.0 is woefully out of date when the upgrade is being attempted.

So, your best option would be to liaise with your Python colleagues in your hospital to see what procedures they follow to be able to install packages using pip when on your hospital’s network. However, as a second best option, it is possible to do a full PyMedPhys upgrade without being able to be connected to PyPI at all. To do that, you need to download all the “wheels” of all the needed packages on another machine that has the same CPU type, operating system and Python version, then copy them across, and then do an offline install on your machine from the downloaded wheels.

To help out, I have downloaded these wheels for you, and zipped them and made them available from the following download link (choose the zip corresponding to your Python version, which you can find by running python --version):

So that others know how to do this themselves, the commands I used to create that zip linked above is the following:

pip install wheel
pip wheel pymedphys[user]==0.35.0 -w .pymedphys-wheels

So, @nancyyu, all you need to do, as long as you have a 64 bit Python install, Windows, and Python 3.6, 3.7 or 3.8, you should be able to download the corresponding zip file linked above, extract the contents of that zip to a directory called C:\Users\YuLit\.pymedphys-wheels, and then run the following:

pip install pymedphys[user]==0.35.0 --no-index --find-links %USERPROFILE%\.pymedphys-wheels

That command says to not use PyPI, but to instead install PyMedPhys from those downloaded and extracted wheel files.

If you happen to have a different system let me know, and I’ll see if I can make a zip file that matches your system.

Keen to hear which approach you choose to go down and if you manage to have success :slight_smile:

Cheers,
Simon

Hi Simon,

Thank you so much for the zip file. Yes I happen to have python 3.7 and windows 64bit. The second best option definitely works. It looks like I have successfully intalled pymedphys and a series of other packages. There was just one error displayed here:

ERROR: botocore 1.19.37 has requirement urllib3<1.27,>=1.25.4; python_version != "3.4", but you'll have urllib3 1.24.2 which is incompatible.

I guess it’s not a critical error and didn’t interfere with the rest of the install. Thank you so much for your help on this. I will follow up with other python colleagues to see what they did to install pip previously.

Also just wondering, in the future if I need to upgrade again using this approach, I do need another similar PC on which pip works and install the wheel in order to generate the zip files. Is that right?

Well, this discussion inspired me to see if I can find a way so that every release in the future will have zips like this made for everyone. See:

So… watch this space? You may just be able to follow the approach you have just undergone in the future, should that approach be what is needed. I’ll let you know how much success I have :slight_smile:. The work on it will be sporadic in the coming evenings, so progress on that front may be slow.

Cheers,
Simon