Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 64
Next »
Background
- These steps assume you're using Windows, so some things may be different on an Apple.
The step-by-step process
- Create a new repository on Bitbucket / GitHub.
- Bitbucket:
- Go to https://bitbucket.org/
- If you need to log in, get the login credentials from LastPass.
- Click the "+" icon in the top left corner and then click 'Repository'.
- Fill out the 'Repository name' field.
- Click the 'Create repository' button.
- You'll be brought to a new webpage.
- Select the URL in the top-right corner of the page.
- Clone the new repository in PythonAnywhere.
- Go to http://pythonanywhere.com/.
- Create a new bash console. (Shortcut)
- Navigate to the directory you'd like this repository to live in.
- Type "git clone ", then paste the URL you copied from Bitbucket into the console (use Ctrl+v) and hit "Enter".
- Give it your Bitbucket password when it asks for it.
- Clone the new repository in SourceTree.
- Open SourceTree on your computer.
- Click 'File' → 'Clone / New'
- A new tab will be created.
- Paste the URL you copied from Bitbucket into the "Source Path / URL" field.
- When you click out of the textbox, if you see an error about not having SSH keys...
- Click "No" in the dialog.
- Generate a public/private key pair with Puttygen.
- Click Tools → Create or Import SSH Keys
- In the Putty Key Generator, click "Generate".
- A bunch of text will appear in the modal. That's the public key.
- Fill out the "Key passphrase" and "Confirm passphrase" fields.
- Click "Save private key".
- Save the file to an easy-to-find directory and name it something memorable.
- Click "Save public key" and name it something like "bitbucket_public_key".
- Save the public key to your Bitbucket account.
- In Bitbucket, select your profile image in the bottom-left, and then click "Bitbucket settings".
- In the Settings page, click "SSH keys".
- Click "Add key".
- Paste in the text from the Puttygen program and give it an easy-to-remember name.
- Add the private key to Pageant on your computer.
- Right-click on Pageant from the Windows task tray and select "Add Key".
- Select the file you saved earlier.
- Go back to SourceTree and try pasting in the URL again and then clicking out of the textbox, and you should see several new options (including the "Clone" button) show up.
- Click "Clone".
- Create a PyCharm project in the new directory that SourceTree created on your hard drive.
- If an existing project opens up:
- Select File → New Project.
- Otherwise, if the "Welcome to PyCharm" window appears...
- Click "Create New Project".
- You'll be presented with a "New Project" window/modal.
- Fill out the fields of the modal.
- Location: Click the "..." button and navigate to the folder created by SourceTree.
- You may need to click into the 'Documents' folder to see the name of the folder, e.g. C:\Users\Nathan\Documents\project_name.
- Interpreter: Ignore this / leave any value; we'll set the interpreter after creating the project.
- Click 'Create'.
- It'll ask you if you want to create the project from existing sources. Click 'Yes'.
- Create a virtualenv with PyCharm.
- With the project open, go to 'File' → 'Settings'
- Navigate to "Project: project_name" → "Project Intepreter"
- Click the gear icon in the top right and select "Create VirtualEnv".
- Fill out the fields in the modal that appears.
- Location:
- Navigate to the project folder.
- Name: Once you've selected the 'Location' field, type 'venv' in the 'Name' field. This will create a new folder named 'venv' in the project folder.
- Base interpreter: I'm guessing it's probably a good idea to set the base Python interpreter to be the same version as that used on PythonAnywhere.
- To get the version used on PythonAnywhere, I start a Python session.
- To install that version of Python, just go to the main Python website.
- When it's installing, I made a note of the directory it was installed to.
- Example: C:\Users\USERNAME\AppData\Local\Programs\Python\Python35\python.exe
- The 'AppData' installation directory didn't show up in PyCharm because it's hidden.
- ...so I navigated to the directory in Windows Explorer and copied the path.
- I then copied that path into PyCharm and added '/python.exe' to the end, and it found the file.
- Inherit global site-packages: Leave this unchecked.
- Make available to all projects: I generally leave this unchecked.
- Click 'OK' in the 'Create Virtual Environment' modal.
- You should see a screen like the one in the image.
- Click 'OK' to save the changes.
- Set up PyCharm to start the virtualenv every time you start a Terminal session.
- Background / Explanation
- We need to do this so that we can generate the 'requirements.txt' file (a later step).
- Step-by-step instructions:
- On the left-side folder-view pane, navigate to 'your_project/venv/Scripts/activate.bat'.
- Right-click the file, and select 'Copy Path'.
- Go to File → Settings → Tools → Terminal → 'Shell path' and add "/K path/to/activate.bat" after the "cmd.exe". (Source)
- Restart PyCharm.
- Start a Terminal session and you should see the name of your virtualenv in parentheses on the command line. Running 'python' should start the version of python that you set earlier.
- Create a 'requirements.txt' file in PyCharm.
- Explanation:
- We're doing this so that we can have our (not-yet-created) PythonAnywhere virtualenv download the necessary packages.
- Step-by-step instructions: (You can find official instructions here.)
- Start a Terminal session and run 'pip freeze > requirements.txt'. (Source)
- (As you can see in the screenshot, it may prompt you to upgrade pip first.)
- The file should appear, and when you open it it should have a list of packages and their versions.
- Use SourceTree to push new files to the Bitbucket repository.
- If you switch back to SourceTree you should see a list of files that SourceTree has noticed as being new.
- Ignore the '.idea/' folder and the 'venv' folder.
- We don't want to have our PyCharm files in the git repository (I think), so navigate to 'Actions' → 'Ignore'
- Select 'Ignore everything beneath: .idea'
- Once that's done those '.idea' files should disappear from the list of Unstaged files.
- Also ignore the venv folder.
- (These pictures were created before I knew to ignore the venv folder, so they show me including the venv folder to be committed. Don't do that.)
- Select the box next to 'Unstaged files' to select the remaining files to be committed.
- (Note: Don't commit virtualenv folder/files to your repository; instead add them to the .gitignore file. These instructions were created before I knew that.)
- Click the 'Commit' button.
- Fill out some brief explanation of what you're committing and click the 'Commit' button.
- Click the 'Push' button.
- Select the 'Push?' box and click 'OK'.
- You should see it switch to a progress bar.
- Once it's finished, you can go to Bitbucket in your browser and confirm that the files were uploaded:
- In PythonAnywhere, pull the new changes.
- Open a bash console and switch into the project folder.
- Run 'git pull'.
- It may prompt you for the Bitbucket password; it's in LastPass.
- Create a virtualenv in PythonAnywhere. (So you'll have one on your computer and one on PA.)
- Run this command: (Source)
mkvirtualenv name_of_your_virtualenv --python=/usr/bin/python3.5
- Name the virtualenv after your project.
- Explanation: The command to activate a virtualenv on PythonAnywhere has global scope (is that the way to describe it?), so you can't name all the virtualenvs "venv"; you'll have a name conflict.
- So your virtualenv on your computer will be named "venv", and your virtualenv on PythonAnywhere will be named after your project.
- Change the version number at the end ("python3.5") to the version of Python you'll be using.
- Note: It looks like specifying the minor version doesn't work. I tried "3.5.2" and it produced an error, but "3.5" worked.
- Install the package requirements in your PythonAnywhere virtualenv.
- Activate the virtualenv with "workon name_of_your_virtualenv".
- Run "pip install -r requirements.txt" (Source)
- In PyCharm, create the default project structure (Source)
project_name/ <-- Usually the same as your module name(?)
MODULENAME/
__init__.py
bin/
.gitkeep
docs/
.gitkeep
setup.py
tests/
MODULENAME_tests.py
__init__.py