Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command prompt execution
#1
My friend has given me a python code and in that project there is a requirements.txt file which contains names of all the packages he installed through pip and another file called setup.py.NOw to run this code through command prompt should i just run “python setup.py install” or do i need to run the requirements.txt file also.
Reply
#2
It's pip install -r requirements.txt.
There may be wheel file that (setup.py can makes).
Then is pip install wheel_name.whl.
wheel contains all,and install needed modules/packages.

This should be done in a virtual environment,to avoid conflict with what you have installed before.
venv is build into Python from 3.6 -->.
Quick demo for Windows, works the same on Linux there can just source bin/activate to activate.
# Make enviroment
C:\code
λ python -m venv my_env

# Cd in
C:\code
λ cd my_env

# Activate
C:\code\my_env
λ C:\code\my_env\Scripts\Activate

# Check that pip point to enviroment
(my_env) C:\code\my_env
λ pip -V
pip 10.0.1 from c:\code\my_env\lib\site-packages\pip (python 3.7)

# Install requirements.txt
(my_env) C:\code\my_env
λ pip install -r requirements.txt
Downloading https://files.pythonhosted.org/packages/eb/01/c1f58987b777d6c4ec535b4e004a4a07bfc9db06f0c7533367ca6da8f2a6/certifi-2017.4.17-py2.py3-none-any.whl (375kB)
    100% |████████████████████████████████| 378kB 1.4MB/s
.......
Reply
#3
(Jul-25-2018, 04:41 PM)snippsat Wrote: It's pip install -r requirements.txt. There may be wheel file that (setup.py can makes). Then is pip install wheel_name.whl. wheel contains all,and install needed modules/packages. This should be done in a virtual environment,to avoid conflict with what you have installed before. venv is build into Python from 3.6 -->. Quick demo for Windows, works the same on Linux there can just source bin/activate to activate.
# Make enviroment C:\code λ python -m venv my_env # Cd in C:\code λ cd my_env # Activate C:\code\my_env λ C:\code\my_env\Scripts\Activate # Check that pip point to enviroment (my_env) C:\code\my_env λ pip -V pip 10.0.1 from c:\code\my_env\lib\site-packages\pip (python 3.7) # Install requirements.txt (my_env) C:\code\my_env λ pip install requirements.txt Collecting requirements.txt Could not find a version that satisfies the requirement requirements.txt (from versions: ) No matching distribution found for requirements.txt You are using pip version 10.0.1, however version 18.0 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. (my_env) C:\code\my_env λ pip install -r requirements.txt Downloading https://files.pythonhosted.org/packages/eb/01/c1f58987b777d6c4ec535b4e004a4a07bfc9db06f0c7533367ca6da8f2a6/certifi-2017.4.17-py2.py3-none-any.whl (375kB) 100% |████████████████████████████████| 378kB 1.4MB/s ....... 
Could you please tell me the sequence of steps i should follow. I m bit confused.my version of python is 2.7.15 and how will i run venv and where should i use setup.py file
Reply
#4
(Jul-25-2018, 04:59 PM)saisankalpj Wrote: I m bit confused.my version of python is 2.7.15 and how will i run venv and where should i use setup.py file
setup.py is really for the person who make the module/package.
You friend should make a wheel for you.
The command to make wheel is python setup.py bdist_wheel.
Then install(this is all you should need to do) with pip install wheel_name.whl(this install all code + module/package).

You should really be using Python 3 and not Python 2.
There is virtualenv for Python 2.

Here a tutorial i made about this subject.
Reply
#5
(Jul-25-2018, 06:32 PM)snippsat Wrote:
(Jul-25-2018, 04:59 PM)saisankalpj Wrote: I m bit confused.my version of python is 2.7.15 and how will i run venv and where should i use setup.py file
setup.py is really for the person who make the module/package.
You friend should make a wheel for you.
The command to make wheel is python setup.py bdist_wheel.
Then install(this is all you should need to do) with pip install wheel_name.whl(this install all code + module/package).

You should really be using Python 3 and not Python 2.
There is virtualenv for Python 2.

Here a tutorial i made about this subject.
After running the python setup.py bdist_wheel i got some extra directories like
1.build
2.egg-info
3.dist
dist contains the wheel file ,so can i remove other directories(build,egg-info) before running pip install wheel_name.whl
Reply
#6
(Jul-26-2018, 10:23 AM)saisankalpj Wrote: dist contains the wheel file ,so can i remove other directories(build,egg-info) before running pip install wheel_name.whl
Yes,you only need wheel file in dist folder,which can be moved and installed wherever pip is available.
Reply
#7
(Jul-26-2018, 04:22 PM)snippsat Wrote:
(Jul-26-2018, 10:23 AM)saisankalpj Wrote: dist contains the wheel file ,so can i remove other directories(build,egg-info) before running pip install wheel_name.whl
Yes,you only need wheel file in dist folder,which can be moved and installed wherever pip is available.
while pushing dist folder in github i am getting a message in githash saying dist folder is ignored by "gitignore" file.then how can i add the dist folder in github??
Reply
#8
Remove dist/ in your .gitignore file.

Usually you to not commit the dist folder.
The repository should have a setup.py file along with the packages and/or modules you're installing.
If you want share your code and easy for other use,then PyPi is normal to use.
So then the content of dist folder(wheel .whl) is uploaded to PyPi then they make it so it will be pip install my_package.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the difference between Command Prompt and Sublimes yaoyao22 1 588 Jul-09-2023, 02:56 PM
Last Post: snippsat
  Facing Problem while opening a file through command prompt vlearner 4 1,857 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,230 Dec-20-2020, 04:23 AM
Last Post: adifrank
  Running Python in Command Prompt Anwar 3 3,002 Nov-15-2020, 03:15 PM
Last Post: snippsat
  starting python from windows command prompt MaartenRo 4 2,746 Sep-04-2020, 12:25 PM
Last Post: MaartenRo
  Will not print in command prompt PandaCode 12 12,824 May-06-2020, 03:48 AM
Last Post: PandaCode
  Script works when executed from command prompt but not when executed in SDP Tippex 0 1,965 Apr-07-2020, 04:26 PM
Last Post: Tippex
  Can read files in command prompt but not IDE Exsul 2 2,120 Sep-13-2019, 01:40 AM
Last Post: jsira2003
  command prompt saisankalpj 8 5,159 Nov-28-2018, 04:13 AM
Last Post: saisankalpj
  Command Prompt Issue benzenegirl 2 2,521 Oct-25-2018, 03:09 PM
Last Post: The_Raven

Forum Jump:

User Panel Messages

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