Here are the steps necessary to setting up a PyCharm Python project with a GitHub Repository. It is not obvious on what to do first: create a PyCharm project and add it to GitHub - or - create a new GitHub repository, clone it and convert it into a PyCharm Python project. Here is the approach I took. This text ist written from the perspective of MacOS.
P.S. PyCharm and IntelliJ are both from JetBrain. No wonder, the look and feel are very simular.
- Overview
- Index
- Syntax
- Check your Python installalation
- Download PyCharm
- Create a Python Project in PyCharm
- Create a GitHub repository
- Prepare the Pycharm Python project to connect to GitHub
- Check for branch name conflicts
- Make changes to your local tree
- Create a Tag
- Project Management using GitHub and Pycharm
[button] - is a button on the screen with the text 'button' on it.
InputField: - is a field labeled 'InputField:', where you can enter text.
<PlaceHolder> - a placeholder to be replaced with your own text (without the '<' and '>').
[v] Label1 - ensure there is a check mark in front of the label 'Label1'
[x] Label2 - ensure there is an 'x' in the check box in front of the label 'Label2'
1/3 - step 1 of in total 3 steps
$ - prompt for a regular user
# - prompt for the root user (system administrator)
It is always a good idea to make sure your installation is current. You do not want to encounter problems, which have already been fixed.
An even better approach is to create a virtual machine with e.g. docker and create your development environment from scratch with each project. In this way, you can also have different environments for different projects at the same time.
Is there a new python version?
Go to MD:python.org
HTML: python.org
Double click the download (Chrome browser: at the bottom margin of the browser).
From a terminal, you can initiate the installation with the command
$ open python-3.9.5-macosx10.9.pkg
Follow the instructions to install python.
Check the version of the current installed conda software.
$ conda --version
Update the conda package manager to the latest version. To actually update, you will have to confirm a prompt.
$ conda update conda
Use conda to update Anaconda to the latest version.
$ conda update anaconda
See also https://docs.anaconda.com/anaconda/install/update-version/
P.S. When using Anaconda, the python version might be slightly older than the publicly available python version.
Execute:
$ python3 --version
Notice: python can install packages with the pip/pip3 command, but python itself can not be updated using the pip/pip3 command.
And execute:
$ pip3 --version
If there is a newer version of pip available, execute
$ pip3 install --upgrade pip
$ pip install --upgrade pip
Other useful pip commands
$ pip3 list # List installed packages
$ pip3 show pip # Show information about installed packages
$ pip list --outdated # Show packages which have an upgrade at pypi
Update all packages installed with pip/pip3:
There is no dedicated command to get to the most current version. Instead you have to create a requirements list using the freeze option.
$ pip freeze > requirements.txt
Edit requirements.txt, and replace all ‘==’ with ‘>=’. Use the ‘Replace All’ command in the editor. Only lines with '==' are relevant. Lines not containing '==' are irrelevant.
$ cat requirements.txt | grep '==' | sed -e 's/==/>=/g' >requirements2.txt
pip install -r requirements2.txt --upgrade
P.S. If you encouunter problems, edit the requirements2.txt file and revert the '>=' back to '==' and rerun the pip install command.
Alternatively:
Open a new python program in PyCharm. If the package needed through import is missing, hover the mouse over the <pkg> name.
from pkg import function
e.g.
from selenium import webdriver
Hover over the 'pkg'. From the popup select 'Install package <pkg>'
$ brew --version
Update the brew package database
$ brew update
Check for outdated packages
$ brew outdated
To make sure, the entire system is using the latest software, it is recommended to reboot your system.
[Jetbrains/pycharm][https://www.jetbrains.com/pycharm/download]
Community
Download .dmg(Intel)
Install from Chrome Downloads.
In the main bar click on Pycharm.
The select 'Check for. Updates...'
If there is an update available, you will see a notification at the bottom right once you open a project.
- Open PyCharm CE
- [New Project]
- Change Location: ~/PycharmProjects/<MyProject>
- [V] Create a main.py welcome script
- [Create]
- Go to the GitHub page of the team leader (If it is just you, you are the team leader):
https://github.com/<team lead> - In the top, black bar click on the + sign
- Select 'New repository'
- Match the name with the local project:
SeleniumEssentialTraining
- Provide a Description
A Pycharm Python project
- [v] Add a README file
- Click [Create repository]
- Capture the URL:
https://github.com/<team lead>/<MyProject>
Notice: There is a pull down button at the top left with a branch icon. This icon indicates, what name is used for the tree. This used to be 'master' and now 'main' is being used. Depending on the git version used on your system, there might be a conflict. Below are instructions on how to resolve this conflict.
7.1 Git init
7.2 Git Remote
7.1.1 Via a terminal
7.1.2 Via PyCharm
$ cd ~/PycharmProjects/<MyProject>
$ git init
- In the top bar, select the VCS tab.
- Enable Version Control Integration...
- Select a version control system to associate with the project root: [Git]
- [OK]
7.2.1 Via a terminal
7.2.2 Via PyCharm
$ git remote add origin https://www.github.com/<team lead>/<MyProject>.git
When you made a mistake with above link, you can remove it with:
$ git remote remove origin
and display your setting with
$ git remote -v
Check the status of git with
$ git status
Please check what name is used for the tree. Look for 'On branch '
- Right click the project
- Select 'Git'
- Select 'Manage Remote...'
- Click on [+]
- Name: origin
- URL: https://github.com/<team lead>/<MyProject>.git
- [OK]
- If you made a mistake with the URL, an error message will pop up and you have a chance to correct your URL
- When the Name and URL have been added, click on [OK]
PyCharm does not have an equivalent to the '$ git status'. Changes to files are indicated by their color. See File Status Highlights for details on the meaning of the colors.
The branch name can be verified by the name in the bottom right margin, next to a lock. Depending on your git version it is either 'Y main' or 'Y master'
Other ways:
- Enter CMD+, or from the top bar, click on PyCharm, Preferences
- Version Control
- Git
- Protected branches: <name>
Or
- Right Click Project
- Git,
- Branches...
- Local Branches
- <name>
In GitHub under https://github.com/<team lead>/<MyProject> in the tab <> Code, there is pulldown menu button to the top left of the page. This button indicates what tree you are currently viewing. By default this is the tree 'main'.
If the local name (e.g. master) and the remote name (e.g. main) do not match, you first have to add something to your local tree so you can give it a new name.
>>>Do not create the change here<<<
The project in GitHub is a GitHub repository and not a PyCharm project. The PyCharm Project is not a GitHub repository. By adding and committing the PyCharm files to the GitHub repository, you have all that is required to synchronize the branch names. The steps needed to synchronize your PyCharm project with the GitHub repository are documented in the next section.
When you enabled your PyCharm Project for GitHub (or # git init), a new .git directory with some configurations files were created. You can now add these files to your local staging area.
9.1 git add
9.2 set remote email and user name
9.3 git commit
9.4 Synchronizing the branch name
9.4.2 Verify the name change
9.5 git commit - name change
9.6 rebase
9.7 git push
9.1.1 Via a terminal
9.1.2 Via PyCharm
$ cd ~/PycharmProject/<MyProject>
$ git add .
Right click on the project <MyProject>
Git
Add or Option+CMD+a
9.2.1 Via a terminal
9.2.2 [Via PyCharm]
Set configuration:
$ git config --global user.email "<mailuser@email.com>"
$ git config --global user.name "<GitHub user>"
Display configuration:
$ git config --list
$ git config --list --show-origin
- Sign out of GitHub
- Enter CMD+, or from the top bar, click on PyCharm, Preferences
- [PyCharm], [Preferences], [Version Control], [GitHub], [+], [Login via GitHub...]
- or [PyCharm], [Preferences], [Version Control], [GitHub], [Log in], [Login via GitHub...]
- [PyCharm], [Preferences], [Appearance & Behavior], [System Settings], [Passwords]
- Do not save, forget passwords after restart
- Click [OK]
By setting the 'Do not save' option, you have the option of choosing which user you are going to use, if you have more than one: a team leader and a group member.
Commit means that the changes are confirmed into the local staging area. The changes will only be updated in the GitHub repository with the 'git push' command in one of the next following sections.
9.3.1 Via a terminal
9.3.2 Via PyCharm
$ git commit -m "Initial Check-in to convert the GitHub repository into a PyCharm project and sync the tree name to 'main'"
Right click on the project <MyProject>
Git
Commit Directory...
A Changelist pops up
In the lower part of the Commit window, provide a Commit Message:
"Initial Check-in to convert the GitHub repository into a PyCharm project and sync the tree name to 'main'"
Click [Commit]
This is only necessary, when the remote branch and the local branch have different names.
9.4.1 Via a terminal
9.4.2 Via PyCharm
$ git rename -M master main
Right click on the project <MyProject>
Git
Branches
Local Branches
Master > Rename...
Exchange 'master' with 'main'
Renaming the tree:
Left click on the tree in the bottom right margin.
Select <master>
Select Rename...
Give the tree its new name: main
Click [Rename]
$ git status
or
bottom right margin
$ git commit -m "branch name change"
You can not commit using PyCharm, because there is no file change.
9.6.1 Via a terminal
9.6.2 Via PyCharm
$ git pull --rebase origin main
*** no satisfying solution for PyCharm yet ***
Not the same as CLI. Does not work.
Right click on the project <MyProject>
Git
Rebase...
git rebase [branch or hash], pulldown
main
[Rebase]
Is this better?
Under git rebase
Click on [Modify options v]
Select another branch to rebase
origin/main main
9.7.1 Via a terminal
9.7.2 Via PyCharm
$ git push --set-upstream origin main
$ git push
Right Click on the project <MyProject>
Git
Push or Shift+CMD+K
main -> origin:main
[Push]
See also Project Management using a PyCharm Python project with a GitHub repository.
Tag your branch, so you can always get back to this point of the repository.
10.1 Via a terminal
10.2 Via PyCharm
$ git tag v1.0
$ git push origin v1.0
Right Click on the project <MyProject>
Git
New Tag...
Tag Name: -- here the letter v is allowed as first character. After that, you should have a sequence of numbers and the period. For example: 'v1.0'. A Tag can not have words like e.g. 'Winter2020/2021'.
Restrictions unclear: 'Commit:' is a reference for a commit Message can be verbous
Git, Push,
[v] Push Tags
Push
By default, the git push command doesn’t transfer tags to remote servers.
$ git push origin
https://git-scm.com/book/en/v2/Git-Basics-Tagging
PyCharm does always create a complete clone with all of its branches. Therefore when starting from the welcome screen with 'Get from Version Control' you will always get all branches, tags, ..
If you have to work on a specific branch/tag, you need to changes branch/tag on the bottom right margin of the screen.
I have not found a way to compare a file against a tagged version.
You can now make changes to your tree, but should if you are working on this tree with a team, you might want to look at: https://gist.github.com/tcd1558/e8491655c039330f9ac1570be5695b63