Skip to end of metadata
Go to start of metadata

  1. Create a new repository on Bitbucket / GitHub.
    1. Bitbucket:
      1. Go to https://bitbucket.org/
        • If you need to log in, get the login credentials from LastPass.
      2. Click 'Repositories' and then 'Create repository'. 
      3. Fill out the 'Repository name' field.
      4. Click the 'Create repository' button.
      5. You'll be brought to a new webpage.
      6. Click "Clone". 
      7. Copy the command it shows you. 
  2. Clone the new repository in PythonAnywhere.
    1. Go to http://pythonanywhere.com/.
    2. Create a new bash console. (Shortcut)
    3. Navigate to the directory you'd like this repository to live in.
    4. Take the command you copied from Bitbucket and paste it into the console and hit "Enter".
    5. It will prompt you for your Bitbucket password; it's in LastPass.
  3. Clone the new repository in SourceTree.
    1. Open SourceTree (it's software you keep on your computer).
    2. Click 'Clone / New' 
    3. A dialog box will pop up. Click the globe icon in the top-right to be shown a list of your online Bitbucket projects. 
    4. Select the project you created earlier.
    5. Click "Clone".
  4. Create a PyCharm project in the new directory that SourceTree created on your hard drive.
    1. In PyCharm, select File → New Project. 
    2. A modal will appear.
    3. Fill out the fields of the modal.
      1. Location: Click the "..." button and navigate to the folder created by SourceTree. 
        1. You may need to click into the 'Documents' folder to see the name of the folder, e.g. C:\Users\Nathan\Documents\project_name.
      2. Interpreter: Ignore this / leave any value; we'll set the interpreter after creating the project.
    4. Click 'Create'. 
    5. It'll ask you if you want to create the project from existing sources. Click 'Yes'. 
  5. Create a virtualenv with PyCharm.
    1. With the project open, go to 'File' → 'Settings' 
    2. Navigate to "Project: project_name" → "Project Intepreter" 
    3. Click the gear icon in the top right and select "Create VirtualEnv". 
    4. Fill out the fields in the modal that appears.
      1. Location:
        1. Navigate to the project folder. 
      2. 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. 
      3. 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.
        1. To get the version used on PythonAnywhere, I start a Python session. 
        2. To install that version of Python, just go to the main Python website. 
        3. When it's installing, I made a note of the directory it was installed to.
          1. Example: C:\Users\USERNAME\AppData\Local\Programs\Python\Python35\python.exe
        4. The 'AppData' installation directory didn't show up in PyCharm because it's hidden. 
        5. ...so I navigated to the directory in Windows Explorer and copied the path. 
        6. I then copied that path into PyCharm and added '/python.exe' to the end, and it found the file. 
      4. Inherit global site-packages: Leave this unchecked.
      5. Make available to all projects: I generally leave this unchecked.
    5. Click 'OK' in the 'Create Virtual Environment' modal.
    6. You should see a screen like the one in the image. 
    7. Click 'OK' to save the changes.
  6. Set up PyCharm to start the virtualenv every time you start a Terminal session.
    1. Background / Explanation
      1. We need to do this so that we can generate the 'requirements.txt' file (a later step).
    2. Step-by-step instructions:
      1. On the left-side folder-view pane, navigate to 'your_project/venv/Scripts/activate.bat'. 
      2. Right-click the file, and select 'Copy Path'. 
      3. Go to File → Settings → Tools → Terminal → 'Shell path' and add "/K path/to/activate.bat" after the "cmd.exe". (Source
      4. Restart PyCharm.
      5. 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. 
  7. Create a 'requirements.txt' file in PyCharm.
    1. Explanation:
      1. We're doing this so that we can have our (not-yet-created) PythonAnywhere virtualenv download the necessary packages.
    2. Step-by-step instructions:  (You can find official instructions here.)
      1. Start a Terminal session and run 'pip freeze > requirements.txt'. (Source
        1. (As you can see in the screenshot, it may prompt you to upgrade pip first.)
        2. The file should appear, and when you open it it should have a list of packages and their versions. 
  8. Use SourceTree to push new files to the Bitbucket repository.
    1. If you switch back to SourceTree you should see a list of files that SourceTree has noticed as being new. 
    2. Ignore the '.idea/' folder and the 'venv' folder.
      1. We don't want to have our PyCharm files in the git repository (I think), so navigate to 'Actions' → 'Ignore' 
      1. Select 'Ignore everything beneath: .idea' 
      1. Once that's done those '.idea' files should disappear from the list of Unstaged files.
      2. Also ignore the venv folder.
        1. (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.)
    3. Select the box next to 'Unstaged files' to select the remaining files to be committed.
      1. (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.) 
    4. Click the 'Commit' button. 
    5. Fill out some brief explanation of what you're committing and click the 'Commit' button. 
    6. Click the 'Push' button. 
    7. Select the 'Push?' box and click 'OK'. 
    8. You should see it switch to a progress bar. 
    9. Once it's finished, you can go to Bitbucket in your browser and confirm that the files were uploaded: 
  9. In PythonAnywhere, pull the new changes.
    1. Open a bash console and switch into the project folder.
    2. Run 'git pull'. 
    3. It may prompt you for the Bitbucket password; it's in LastPass.
  10. Create a virtualenv in PythonAnywhere. (So you'll have one on your computer and one on PA.)
    1. Run this command: (Source)
      1. mkvirtualenv name_of_your_virtualenv --python=/usr/bin/python3.5
        1. Name the virtualenv after your project.
          1. 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.
            1. So your virtualenv on your computer will be named "venv", and your virtualenv on PythonAnywhere will be named after your project.
        2. Change the version number at the end ("python3.5") to the version of Python you'll be using.
          1. 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.
  11. Install the package requirements in your PythonAnywhere virtualenv.
    1. Activate the virtualenv with "workon name_of_your_virtualenv".
    2. Run "pip install -r requirements.txt" (Source
  12. In PyCharm, create the default project structure (Source)
    1. Default Python project folder structure
      project_name/  <-- Usually the same as your module name(?)
           MODULENAME/
               __init__.py
           bin/
      		.gitkeep
           docs/
      		.gitkeep
           setup.py
           tests/
               MODULENAME_tests.py
               __init__.py
  • No labels