DLS 1 - My own project in PyCharm

Hi Paul (@paulinpaloalto),

many thanks for your reply. This is a follow-up for everyone interested.

Here is what I did to get the assignment source code running on my Windows laptop using PyCharm it running.

Initial Situation
Before getting started to try to get DLS 1 Week 4 Assignment 2 running on my system, I already had Pycharm, Python 3.10.1, and 3.8.10 installed on my Windows laptop.

Steps:

  1. FIND OUT ABOUT THE SYSTEM CONFIGURATION USED IN THE COURSERA ASSIGNMENT
    a. On the assignment page I (miss-)used one of the coding blocks to run your recommended command:
import sys
print(f"python version {sys.version}")

The output:
python version 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20)
[GCC 7.3.0]

I checked conda-forge to find this pre-configured setup, but would not be able to find it. I guess it’s held in a private account and not made public by Coursera?

b. So I moved on to ask the system itself in a terminal window (BTW: For copy/paste I was only able to use a right mouse click inside the terminal. Keyboard shortcut would not work for me.).
Here is how to get there: From the assignment page got to “File” (top left) and then “Open”. In the new window with the folder view go to “New” (top right) and select “Terminal” from the drop-down.

c. In this terminal window I ran this command to find out about the python version in use:

!python -V

Then I tried to find out everything possible about the installed packages. Therefore, go to the project folder:
cd release/W4A2

Install pipreqs:
pip install pipreqs

Run this command:
pipreqs --encoding utf-8 "/home/jovyan/work/release/W4A2" --force

This will create a file named “requirements.txt” in the same folder. You can download it in the folder view window (assignment page → “Open”) by ticking the checkbox in front of the file. This will add a “Download” button in the top row of buttons.

In addition to that I also ran these commands:

conda list --export > requirements-conda_list.txt
pip freeze > requirements-pip_freeze.txt

(And later compared the 3 lists using Excel.)

Now I downloaded all 3 files onto my Windows laptop. Also, make sure to download all other files/folders that are relevant to run the source code.

  1. REPRODUCING THE SAME ENVIRONMENT ON MY WINDOWS LAPTOP

a. First thing I needed was to install Python 3.7.6 in addition to the other two versions. I downloaded it from here:

Python Downloads

Then I used the following two URLs to install “Python 3.7.6” as well as “virtualenv” and “miniconda” on my Windows system.

Installing-multiple-python-versions-on-windows-using-virtualenv
How-to-run-multiple-python-versions-on-windows

Activate virtualenv at the end. (I’m not sure if “miniconda” is really needed?)

b. Next, I started PyCharm and created a new project. Make sure, to set the correct interpreter for the project. Use Ctrl+Alt+S to open Settings and select “Project:YourProjectname” → Python interpreter. Then I realized that installing the old packages from this PyCharm Settings window does not work as shown in this image:

PyCharm Settings Image

The older versions are not offered there. Now I added the conda-forge channel to PyCharm. Again, I’m not sure if this was needed or not. Here you can see how to add the channel:

Adding conda-forge channel

c. Now I first got all the source code from the assignment page and copy-pasted it into the “main.py” of PyCharm and tried to run it. Now there were a couple of minor things to correct in source code (spaces, type of quotes, …) but when it came to the import messages I did this:
Configure the terminal “File → Settings → Tools → Terminal”. I changed the application setting to this shell path:

“C:\WINDOWS\system32\cmd.exe”

Also, check “Shell integration” as well as “Activate virtualenv”.
Open the terminal window inside of PyCharm with: “View → Tools Windows → Terminal”. And then for each missing library, I ran one command which was created with the help of the “requirement.txt” files that were created in step 1. I checked those files to make sure I use the correct version.

d. First, go to the location of the Python interpreter
cd C:\Users\User\AppData\Local\Programs\Python\Python37

Then run this/these command/s to change the verion or install a specific verion:

python -m pip install --upgrade pip==20.1.1
python -m pip install --upgrade setuptools==46.1.3
python -m pip install --upgrade numpy==1.18.4
python -m pip install --upgrade h5py==2.10.0
python -m pip install --upgrade matplotlib==3.2.1
python -m pip install --upgrade scipy==1.4.1
python -m pip install --upgrade pillow==7.1.2

Trying to upgrade/install PIL gave me an error. So I came across this post:
Get-error-when-try-to-install-pil
And then installed pillow as shown above.

e. Basically, you should be up and running now. However, I figured that these two lines in the assignment source code do not work:

%load_ext autoreload
%autoreload 2

I commented them out and instead added:

plt.show()

… after each plt.imshow(…) to see all plotted images.

The thing that “autoreload” does not work, is a bit of a hassle. You need to run the entire thing each time you change something. The training results of the Neural Network for example are not “remembered” so that you could easily re-run another cat picture. I found URLs discussing this issue, but have not yet managed to make that work for me. If you (reading this post) find a solution, I’d be happy to hear about your solution to this.

How-to-use-ipython-magic-within-a-script-to-auto-reload-modules

UPDATE: These two links helped me:
How to add and configure code cells in PyCharm Community Edition

Pycharm-run-only-part-of-my-python-file

Not immediately but somehow it works now. I think the “trick” is to run the entire code cell by cell first and watch the “Python Console” during that time. Then when you are at the desired cell, you can re-run that cell and it will work.

I hope all this info is helpful to someone. Thanks.

Here are some links that helped me to manage:

https://www.google.com/search?q=pip+install+requirements.txt&rlz=1C1ONGR_deDE944DE944&oq=pip+install+re&aqs=chrome.0.0i512l3j69i57j0i20i263i512j69i60l3.6370j0j7&sourceid=chrome&ie=UTF-8

https://docs.conda.io/en/latest/miniconda.html

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

8 Likes
Good way to run notebooks locally?
C4 W2 EX2 TFOpLambda instead of TensorFlowOpLayer
Error in transfer learning
Subscription over, but why can't access completed assignments?
Not Getting Same Results in Colab
About convolutional network week 4 - Neural Style Transfer, assignment
YOLO lab week 3
Advice needed for AI / ML / DL libraries & tools
General question about project
Course 2 - Week 3 assignment - Exercise 3: one_hot_matrix
Course 2, week 2, optimization, minibatches, test error: "wrong values"
Python version local install?
DLS 2, Week 1, Programming Asssignment, Node: 'sequential/conv2d/Conv2D', DNN library is not found
Improvise_a_Jazz_Solo_with_an_LSTM_Network_v4 in PC
All tests passed in browser (Jupyter), but not local
Accessing Assignments After DLS Completion
Week 2 Residual networks: I get AssertionError: Wrong values when training=False:
Program Assignments in Local Environments
FAQ: Frequently Asked Questions for all MLS Courses
Running Course 4 Week 4 Face Recognition Programming Assignment notebook offline
Coding environment (Colab tips)
Course 4 week 2 assignment 1 exercise 1 identity block
Urgent inquires
View visualizations using python(.py) files, outside of Coursera jupyter notebook
Docker Image for Running Jupyter Notebooks Locally
ValueError: bad marshal data (unknown type code)
MLS Course 1 Week 1 - Cost function-from lab_utils_uni import plt_intuition, plt_stationary, plt_update_onclick, soup_bowl
C1_W2_Lab03_Feature_Scaling_and_Learning_Rate (Multi Variable)
How to setup the environment for this course
Week 4 Assignment 1 3.1 model won't load - "bad marshal data"
W1 (code not running) TypeError: the 'package' argument is required to perform a relative import for './deeplearning'
Coding the assignments in my PC. What should i know?
C2W1 can't import tensorflow.keras.models
Course 1 Week3 Lab1
Seeking Help: Requesting a Functional Anaconda Environment (environment.yml) for Jupyter Notebook Visualization
Cannot render markdown table and latex correctly
Kernel stops on C4 Wk3
C1_W1_Lab03_Cost_function_Soln graph interaction
DLS issue in running C4_W4_Assignment2 on local machine
Having problems running the labs on my device
Interactive coding for lucrative visuals
C1_W1_Lab03_Cost_function_Soln
Error in Lab files when running outside lab sandbox- Car detection with YOLO- ImageDraw.textsize() deprecated
How to download and install Neural Network assignments locally
C2W2A1 optimization methods
Ex4 fails on my local PC environment, while same code passes on Jupyter cloter
Having strange bug report running notebooks offline
C2_W3 lab 1 regression with perceptron - getting errors in last 2 cells of notebook
CategoricalAccuracy' object has no attribute 'reset_states
CategoricalAccuracy' object has no attribute 'reset_states
How Can rerun programming assignment on my laptop
DLS2 WK1 Regularization Lab
Face Recognition assignment `model_from_json()` `TypeError: Could not locate class 'Functional'.`
C5_W1: Shakespeare poem character-level generation load_model fails in latest version of the ecosystem. :-1:
Help! Got different results when running code in C2W2 Notebook locally and remotely!
TensorFlow Setup
Course Lab Error
Running Options Labs locally on Jupyter NOtebook
Error Executing W3 Optional Lab 2 Sigmoid Function
Week 4 Transformer Network: package versions
Week 1 Regularization assignment : Unable to load the data
Unable to import transformers using my jupyter notebook
How to download all Lab material(notebook files, images, *.txt , folder, sub-folder)
Best method for downloading the lab notebooks?
TF, Python, etc. library versions required for Jupyter and Google Collab Lab code
Does it matter if you take Course 5 before Course 4?
Conda env for notebook of programming assignment
Week2 Assignment - Residual Networks
Error in import h5py when running on local machine
Not able to complete the course in the required timing
Run copy of lab assignments in local jupyter lab--re_utils error
Access to completed programming assignments
All the files have been downloaded, but can not run on my own comuputer
Why does this error come up?
Course 4 week 2 multiclass image classification
InvalidArgumentError
ResNet C4 W2 A1- Ex2 convolutional_block. Error: AssertionError: Wrong values when training=False
Untar files please help
Week 1 Assignments missing library