Site icon EASY2DIGITAL

Chapter 1 – Ways to Install and Set up Python Environment in MacBook OS

Digital marketing has become so sophisticated and data-oriented in the present-day marketing field. First-hand external data and deeper in-house data analytics influence digital marketing strategies and performance optimization. No matter what marketing position you are in, or what business model you’re running.

If you were an eCommerce marketer

Python must be your good partner to automatically index supplier and opponent product market pricing information. They are integrated with your profit calculator, for example, specify to fetch and scrape web data.

If you were a social media marketer

Python can help you automatically scrape a list of the right potential collaborated influencer profiles from multi-social channels. It’s based on what posts they blast and what content is, for example, they Scrape Youtubers’ videos via Youtube API, and scrape top Instagram posts, and user profiles.

The fact

There are too many application scenarios to illustrate all benefits of Python for digital markets. But the main goal of a successful digital marketing strategy is to achieve a marketing return on investment ROI greater and faster. It is impossible without using the technologies like Python for automating the process.

So based on my past agency and client-side experience, in this Python Tutorial, I’ll attempt to share a collection of Python Tutorials for digital marketers. And in this Python Tutorial, I would start with how to install and set up Python3, and I’ll take Mac as an example.

1. Set up Python 3

Before downloading and installing the latest Python version, it might be better to open a Mac notebook terminal and check which default Python version is being run in your Mac notebook. 

The reason we suggest you do this action is that for the Mac notebook, Python 2.7 is pre-installed. But an out-of-date version of Python, version 2.7 was officially deprecated on January 1st, 2020. This means you need to update it to version 3,  before building any new projects in your local development environment. So we can go to Terminal and check if your Mac notebook is still equipped with the default Python version.

And as you can see from the screencap after typing in the python –version, my Macbook Python version is 2.7.16. So for using Python 3, we need to go to download the Python3 version.

Python 3 is an open-source file, and you can go to this website and download it. After you complete the download, it’s very straightforward to open the file and proceed with the installation as well as the other App installation process.

After you install Python3, you can go back to the terminal and type in 

python --version

However as you can see from the screencap, you find out the default version is still Python2. The reason for this is that the installation process is just to create a command of Python3, rather than replacing the default version. If you type in 

python3 --version

You can find the result in python 3.9.0, which means you’ve installed the Python3 command and you can use it to activate the value.

Being said that you can create an association between python and python3 in your Mac notebook by using an alias ($ nano ~/.bash_profile). But I’m not going to deep dive into details here, but I’ll elaborate on this association in the coming chapters of the Python tutorial.

2. Test Python3 and Run your first Python code & file

Now you can test the function running within the Python3 shell in your Mac terminal. 

First of all, you can type in python3, and you can see there’s a new section coming up in the terminal. This is a shell you can run python code and functions.

For example, you can input some functions such as:

print(‘heelo’)

Or create a variable

1) X = 10

2) print(x)

Apart from running a single line of code and function, you can test to create a py file for running in Mac terminal later. There are many free available Python editors you can use out there, such as sublime text. And here I’ll take Idle as an example because it comes along with the downloaded Python file.

You can double-click idle and there’s a window coming up that is the idle shell for you to run codes and functions

Then, you can create a new file and create a single line of code, and save it as a new .py file

print(‘hello’)

3. Run the python script file in Mac Terminal

The python script file currently is pretty simple, but in the future when you pick up advanced web scraping skills, this is the module you might create and use for scraping your opponent’s huge line of product pricing.

Back to the Mac terminal, you can try to run this .py file there. Before typing in the code, please copy the .py file path, or you can use a shortcut path expression like the one below.

Python3 ~/desktop/intro.py

Just kindly remind to use the command python3, because the default Mac Python is still the 2.0 version

When this step is done, it proves that you have successfully installed Python3.

I hope you enjoy reading Python Tutorial for Digital Marketers 1: Install and Set up Python for Mac. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

If you are interested in learning the next chapter, please click the article below

Chapter 2: Web Scraping with BeautifulSoup, Requests, Python

FAQ:

Q1: What are the system requirements for Python installation on a Macbook?

A: To install Python on a Macbook, you need a Macbook running macOS 10.9 or later with at least 1 GB of free disk space and 2 GB of RAM.

Q2: How can I check if Python is already installed on my Macbook?

A: You can check if Python is already installed on your Macbook by opening the Terminal application and typing ‘python –version’. If Python is installed, it will display the version number.

Q3: How do I download Python for Macbook?

A: To download Python for Macbook, you can visit the official Python website at python.org and navigate to the Downloads section. From there, you can select the macOS installer corresponding to your version of macOS.

Q4: Can I have multiple versions of Python installed on my Macbook?

A: Yes, you can have multiple versions of Python installed on your Macbook. However, it is recommended to use a version manager like pyenv to manage multiple Python installations.

Q5: How do I install Python on my Macbook using the command line?

A: To install Python on your Macbook using the command line, you can use a package manager like Homebrew. Open the Terminal application and run the command ‘brew install python’ to install the latest version of Python.

Q6: What IDEs or text editors can I use with Python on my Macbook?

A: There are several popular IDEs and text editors that you can use with Python on your Macbook, such as PyCharm, Visual Studio Code, Sublime Text, and Atom.

Q7: How do I set up a virtual environment for Python on my Macbook?

A: To set up a virtual environment for Python on your Macbook, you can use the ‘venv’ module that comes bundled with Python. Open the Terminal application, navigate to your project directory, and run the command ‘python3 -m venv env’ to create a new virtual environment.

Q8: How do I activate a virtual environment for Python on my Macbook?

A: To activate a virtual environment for Python on your Macbook, open the Terminal application, navigate to your project directory, and run the command ‘source env/bin/activate’. This will activate the virtual environment and any Python commands or packages you install will be isolated to that environment.

Q9: How do I install Python packages using pip in my virtual environment on a Macbook?

A: To install Python packages using pip in your virtual environment on a Macbook, first activate the virtual environment as mentioned in the previous answer. Then, you can use the command ‘pip install package_name’ to install the desired package.

Q10: How do I uninstall Python from my Macbook?

A: To uninstall Python from your Macbook, you can use the Terminal application and run the command ‘sudo rm -rf /Library/Frameworks/Python.framework’ to remove the Python installation. However, be cautious while uninstalling as it may affect other applications that rely on Python.

Exit mobile version