Python Forum
using self-developed modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using self-developed modules
#10
I don't know what your problem is now.

Can show a example with virtual environment,this is now build into Python trough venv.
Then use selfwrittenmodule.py my version that return something,your should also return something.
# selfwrittenmodule.py
def f1(x):
    x = x + 1
    return x
This will be "like a" new python installation,separate from OS Python.
Can maybe help looking at it from an other prescriptive.
# Test python
C:\data
λ python -c "import sys; print(sys.executable)"
C:\python37\python.exe

# Test pip
C:\data
λ pip -V
pip 19.2.1 from c:\python37\lib\site-packages\pip (python 3.7)

# Make virtual environment 
C:\data
λ python -m venv my_code

# Cd in
C:\data
λ cd my_code

# Activate see now (my_code)
C:\data\my_code
λ C:\data\my_code\Scripts\activate

# Now will python and pip only point to this folder,as long as active
(my_code) C:\data\my_code
λ python -c "import sys; print(sys.executable)"
C:\data\my_code\Scripts\python.exe

(my_code) C:\data\my_code
λ pip -V
pip 19.0.3 from c:\data\my_code\lib\site-packages\pip (python 3.7)
Now if save selfwrittenmodule.py in c:\data\my_code\lib\site-packages

See that work fine from my_code folder.
(my_code) C:\data\my_code
λ python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import selfwrittenmodule
>>>
>>> selfwrittenmodule.f1(999)
1000

# Placement
>>> selfwrittenmodule.__file__
'C:\\data\\my_code\\lib\\site-packages\\selfwrittenmodule.py'
>>> exit()
Install 3-party package eg Requests will aslo go into site-packages folder as all 3-party packages/modules dos.
(my_code) C:\data\my_code
λ pip install requests
Collecting requests .....  
Successfully installed certifi-2019.6.16 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.3
Usage test:
(my_code) C:\data\my_code
λ python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
>>> r = requests.get('http://python-forum.io')
>>> r.status_code
200

>>> r.text[494:520]
'Welcome to python-forum.io'

# Placement
>>> requests.__file__
'C:\\data\\my_code\\lib\\site-packages\\requests\\__init__.py'
Reply


Messages In This Thread
using self-developed modules - by wlp - Aug-28-2019, 03:04 PM
RE: using self-developed modules - by wlp - Aug-28-2019, 04:05 PM
RE: using self-developed modules - by snippsat - Aug-28-2019, 05:41 PM
RE: using self-developed modules - by wlp - Aug-29-2019, 10:36 AM
RE: using self-developed modules - by perfringo - Aug-29-2019, 11:22 AM
RE: using self-developed modules - by snippsat - Aug-29-2019, 03:29 PM
RE: using self-developed modules - by wlp - Aug-29-2019, 04:18 PM
RE: using self-developed modules - by snippsat - Aug-29-2019, 05:20 PM
RE: using self-developed modules - by wlp - Aug-30-2019, 02:18 PM
RE: using self-developed modules - by snippsat - Aug-30-2019, 03:17 PM
RE: using self-developed modules - by wlp - Aug-30-2019, 04:16 PM
RE: using self-developed modules - by snippsat - Aug-30-2019, 07:10 PM
RE: using self-developed modules - by wlp - Aug-31-2019, 01:45 PM
RE: using self-developed modules - by snippsat - Aug-31-2019, 05:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Developed App in VS2019 - Help with pyinstaller fioranosnake 0 1,630 Nov-11-2019, 09:12 PM
Last Post: fioranosnake
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,520 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020