Python And Python Package Installation

When I tried to set up APIs, I came across the problem of installing custom packages and spent quite a lot of time figuring out how. It involves also figuring out the path, environment of Python that I installed in the very beginning. It’s time worthy to dig deeper to grasp both.

I have been using Anaconda and its associated interface Spyder. Since there are two versions Python 2 and Python3, I installed both. Their paths are:

import sys; sys.path


Similarly, version 2 path is:


I also installed python without Anaconda under these paths: ”, ‘C:\Users\ncarucci\AppData\Local\Programs\Python\Python37\’, ‘C:\Users\ncarucci\AppData\Local\Programs\Python\Python37\DLLs’, ‘C:\Users\ncarucci\AppData\Local\Programs\Python\Python37\lib’, ‘C:\Users\ncarucci\AppData\Local\Programs\Python\Python37’, ‘C:\Users\ncarucci\AppData\Local\Programs\Python\Python37\lib\site-packages’

Next, when I worked on Django projects, it is optimal to work in a virtual environment, so all dependency version updates etc. can be managed easily. with respect to how to install virtual environment, here is what I pasted from my description on documenting a complete web algo, “create an virtual environment by typing “virtualenv env_site1″ in the cmd (command prompt or shell in windows), I will then apply all apps/webs within this virtual environment going forward. to make it work, first activate: C:\Users\ncarucci\env_site1\Scripts>activate, then it shows ” (env_site1) C:\Users\ncarucci\env_site1\” before prompt.

Now I will install Django by ” (env_site1) C:\Users\ncarucci\env_site1\Scripts>pip install django “, then enter python to enter to shell, type >>> import django, >>> django.get_version() 2.2.1′.

Exit from python shell, go up to the folder of env_site1, type “django-admin startproject sampsite” to create this app/web called sampsite. Type “python runserver”, ” to start development server at ”.

I notice it is different than the instruction on the hitchhiker’s guide, where you type pip install –user pipenv, then enter

$ cd project_folder
$ pipenv install requests

This is exactly what I followed to install factset PA Engine API, I created the project folder C:\Users\ncarucci\Documents\Python Scripts\PAAPI\Engines Python SDK v2 2.0.0>, then cd into this folder, then to pip install fds.protobuf.stach-1.0.0.tar.gz. Note I didn’t use virtual env in this case.

It ran smoothly, however, what on earth is the installation of packages doing? Where do the key files go and stay?

From above pip install, it went to the core Python folder: c:\users\ncarucci\appdata\local\programs\python\python37\lib\site-packages

So when I use Anaconda to pull up Spyder to run the interpreter, this path is not recognized, I need to manually set up the path by typing

import sys

Another problem I encountered is a custom py file, I want to use it as a module to import and then run the objects under this class/module. How to do it?

A workaround is to store the py file in the right place, and then type

import sys

However, the proper practice is to set path included and apply import commands as regular modules. This stackoverflow post offers multiple ways.

sys.path.append(‘C:\\Users\\ncarucci\\Documents\\Python Scripts\\PAAPI\\Engines Python SDK v2 2.0.0’)
from stach_extension import StachExtensions

Lastly, I want to peek into the environmental variable setting. According to Microsoft web page, ” Environment variables specify search paths for files, directories for temporary files, application-specific options, and other similar information. The system maintains an environment block for each user and one for the computer.” My setting so far is

I recall the first time I setup is to type directly in CMD “set PATH=%PATH%; C:\\users\\ncarucci\\appdata\\local\\programs\\python\\python37 didn’t work, so I turn to the pop-up windows environmental variable setting to manually enter “%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;%USERPROFILE%\AppData\Local\Programs\Python\Python37\Scripts;%USERPROFILE%\AppData\Local\Programs\Python\Python37;”. I notice that I have to follow/use %USERPROFILE% instead of c:\users\ncarucci here for it to work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.