Suppose you wrote a python code which does certain operations (taking in excel data, perform analysis, giving out a excel data with graphs). You can do it because you have Python installed on your laptop. But how does your colleague work with the same code, if he want to use it?
Step 1: Save the file, which you want make as an executable as filename.py in directory C:\Users\yourname
Step 2: Create an environment using command prompt so that the executable file can be made within the environment
C:\Users\yourname> mkdir Envirornments
Step 3: Go to the environment by typing following in command prompt: C:\Users\yourname> cd Environments
Next thing will appear: C:\Users\yourname\Environments
Step 4: Create a new project environment, type following:
C:\Users\yourname\Environments>virtualenv project2_env
Step 5: Give project a name into the environment, type following:
C:\Users\yourname\Environments>cd project2_env
Step 6: Activate the project, type following:
C:\Users\yourname\Environments\project2_env>Scripts\activate
Step 7: Install required packages for your python file, including pyinstaller:
(project2_env)C:\Users\yourname\Environments\project2_env>pip install package1
(project2_env)C:\Users\yourname\Environments\project2_env>pip install package2
(project2_env)C:\Users\yourname\Environments\project2_env>pip install package3
(project2_env)C:\Users\yourname\Environments\project2_env>pip install pyinstaller
Step 8: Copy paste the python file from step 1 to the environments folder.
Step 9: Create the executable file, type following:
(project2_env)C:\Users\yourname\Environments\project2_env> pyinstaller — onefile -w filename.py
Anaconda will make an executable file with the filename in the folder 'dist'. The file has python image on it and usually the largest size within the folder.
If you double click the file, it will start running.
Related
I use it on my windows machine by downloading its binary. I also use it in Heroku from its herokus build pack. I don't know what operating system replit use. But I try every possible commed like.
!pip install ta-lib
!pip install talib-binary
It's not working with replit. I thought it work like google co-lab but its not the same.
can anyone use TA-LIB with replit. if so. How you install it?
Getting TA-Lib work on Replit
(by installing it from sources)
Create a new replit with Nix toolset with a Python template.
In main.py write:
import talib
print (talib.__ta_version__)
This will be our test case. If ta-lib is installed the python main.py (executed in Shell) will return something like:
$ python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
We need to prepare a tools for building TA-Lib sources. There is a replit.nix file in your project's root folder (in my case it was ~/BrownDutifulLinux). Every time you execute a command like cmake the Nix reports that:
cmake: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
cmake.out
cmakeCurses.out
cmakeWithGui.out
cmakeMinimal.out
cmake_2_8.out
If you select cmake.out it will add a record about it into the replit.nix file. And next time you call cmake, it will know which cmake version to launch. Perhaps you may manually edit replit.nix file... But if you're going to add such commands in a my way, note that you must execute them in Shell in your project root folder as replit.nix file is located in it. Otherwise Nix won't remember your choice.
After all my replit.nix file (you may see its content with cat replit.nix) content was:
{ pkgs }: {
deps = [
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
pkgs.python38Full
];
env = {
PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
# Needed for pandas / numpy
pkgs.stdenv.cc.cc.lib
pkgs.zlib
# Needed for pygame
pkgs.glib
# Needed for matplotlib
pkgs.xorg.libX11
];
PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
LANG = "en_US.UTF-8";
};
}
Which means I executed libtool, autoconf, automake and cmake in Shell. I always choose a generic suggestion from Nix, without a specific version. Note: some commands may report errors as we executing them in a wrong way just to add to a replit.nix.
3.
Once build tools are set up we need to get and build TA-Lib C library sources. To do that execute in Shell:
git clone https://github.com/TA-Lib/ta-lib.git
then
cd ta-lib/
libtoolize
autoreconf --install
./configure
If configure script is completed without any problems, build the library with:
make -j4
It will end up with some compilation errors, but they are related to some additional tools which are used to add new TA-Lib indicators and build at the end, but not the library itself. The library will be successfully compiled and you should be able to see it with:
$ ls ./src/.libs/
libta_lib.a libta_lib.lai libta_lib.so.0
libta_lib.la libta_lib.so libta_lib.so.0.0.0
Now we have our C library built, but we can't install it to a system default folders. So we have to use the library as is from the folders where it was build. All we need is just one more additional preparation:
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
This will copy a library headers to a subfolder, as they are designed to be used from a such subfolder (which they don't have due to impossibility to perform the installation step).
4.
Now we have TA-Lib C library built and prepared to be used locally from its build folders. All we need after that - is to compile the Python wrapper for it. But Python wrapper will look for a library only in system default folders, so we need to instruct it where our library is.
To do this, execute pwd and remember the absolute path to your project's root folder. In my case it was:
/home/runner/FormalPleasedOffice
Then adjust the paths (there are two) in a following command to lead to your project path:
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
This is one line command, not a two commands.If the paths would be shorter it would look like:
TA_INCLUDE_PATH=/path1/ TA_LIBRARY_PATH=/path2/ pip install ta-lib.
After execution of this command the wrapper will be installed with two additional paths where it will look for a library and its header files.
That's actually all.
An alternative way would be to clone the wrapper sources, edit its setup.py and install wrapper manually. Just for the record this would be:
cd ~/Your_project
git clone https://github.com/mrjbq7/ta-lib.git ta-lib-wrapper
cd ta-lib-wrapper
Here edit the setup.py. Find the lines include_dirs = [ and library_dirs = [ and append your paths to these lists. Then you just need to:
python setup.py build
pip install .
Note the dot at the end.
5.
Go to the project's folder and try our python script:
$python main.py
b'0.6.0-dev (Jan 1 1980 00:00:00)'
Bingo!
The #truf answer is correct.
after you add the
pkgs.libtool
pkgs.automake
pkgs.autoconf
pkgs.cmake
in the replit.nix dippendancies.
git clone https://github.com/TA-Lib/ta-lib.git
cd ta-lib/
libtoolize
autoreconf --install
./configure
make -j4
mkdir ./include/ta-lib
cp ./include/*.h ./include/ta-lib/
TA_INCLUDE_PATH=/home/runner/FormalPleasedOffice/ta-lib/include/ TA_LIBRARY_PATH=/home/runner/FormalPleasedOffice/ta-lib/src/.libs/ pip install ta-lib
Note : FormalPleasedOffice should be your project name
Done.
Here is the youtube video :
https://www.youtube.com/watch?v=u20y-nUMo5I
So I recenetly installed ROS on my system after which I cannot create a python virtual environment without the ROS dependencies. This is my pip3 freeze's output. I have truncated the ouput to fit StackOverflow's standards.
dynamic-reconfigure==1.7.1
gazebo-plugins==2.9.2
gazebo-ros==2.9.2
gencpp==0.6.5
geneus==3.0.0
genlisp==0.4.18
genmsg==0.5.16
gennodejs==2.0.2
genpy==0.6.15
image-geometry==1.15.0
interactive-markers==1.12.0
joint-state-publisher==1.15.0
joint-state-publisher-gui==1.15.0
laser-geometry==1.6.7
message-filters==1.15.11
python-qt-binding==0.4.4
qt-dotgraph==0.4.2
qt-gui==0.4.2
qt-gui-cpp==0.4.2
qt-gui-py-common==0.4.2
resource-retriever==1.12.6
rosbag==1.15.11
rosboost-cfg==1.15.8
rosclean==1.15.8
roscreate==1.15.8
rosgraph==1.15.11
roslaunch==1.15.11
roslib==1.15.8
roslint==0.12.0
roslz4==1.15.11
rosmake==1.15.8
rosmaster==1.15.11
rosmsg==1.15.11
rosnode==1.15.11
rosparam==1.15.11
rospy==1.15.11
rosservice==1.15.11
rostest==1.15.11
rostopic==1.15.11
rosunit==1.15.8
roswtf==1.15.11
rqt-action==0.4.9
rqt-bag==0.5.1
rqt-bag-plugins==0.5.1
rqt-console==0.4.11
You followed all of the ROS install instructions from the wiki. The last step is adding the command source /opt/ros/{distro}/setup.bash to your .bashrc file. This is the command that actually setups your PYTHONPATH and other needed variables.
If you don't want it to be automatically added you can simple remove that line from your bashrc. You'll just have to manually source the file from now on.
I have a simple scipt that gives me the time to a specific date and i'm using pyinstaller with this command to convert it to a .exe file to give to my friend:
pyinstaller --onefile --windowed "D:/Documents/code/own/python/sages_birthday/time_till_meetup.py"
When i then try to execute the created file i get this window as an error:
I have made a file with --console instead of --windowed to try and get more information, but i didn't even get the error to pop up or any other information.
Step 1: Add Python to Windows Path
Step 2: Open the Windows Command Prompt
Step 3: Install the Pyinstaller Package
pip install pyinstaller
Step 4: Save your Python Script
Step 5: Create the Executable using Pyinstaller
cd followed by the location where your Python script is stored
Step 6: pyinstaller --onefile pythonScriptName.py
Step 7: Run the Executable
Few additional files got created at that location. To find the executable
file, open the dist folder:
I created my own python packages that contains some script. It can be installed with
python setup.py install
Under Linux I can then run the script when the correct conda environment is loaded with:
my_script.py
Under Windows the script is not found although I specify it twice in the setup.py file:
config = {
...
'version': '0.0.25',
'scripts': ['scripts/my_script.py', 'scripts/my_script.bat'],
'packages': ['my_package'],
'name': 'ms_package',
'data_files': [('scripts', ['scripts/my_script.py', 'scripts/my_script.bat']),
('static', ['static/my_data.csv'])]
}
The script starts with a shebang:
#!/usr/env python
The file is found, but when I run it I get the message that this file has not app associated. How to set this up correctly under Windows? Do I need a second file that specifies an app?
I added the my_script.bat that loads the anaconda environment, but then fails with the same error. And when I put
python my_script.py
in there, it does not find my_script. So, I would have to do something equivalent to
python `which my_script.py`
Is there a functionality like this on Windows (Windows 10)?
I would like to have an icon for the user to click on. For people that don't know how to use the command line.
I'm using setuptools for python packaging where I define console script entry points the usual way in the setup.py file:
setup.py
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(...
name='my_project',
entry_points={'console_scripts':['my_entry_name=my_package.scripts.my_python_script:main'
]},
...
)
After installing the package, I can call this entry point from a batch file like this:
my_CURRENT_batch_file.command
#!/bin/bash
cd "$(dirname "$0")" # set the working directory as the command file locations
~/anaconda3/envs/my_env_name/bin/entry_point_name <my script args>
While this works, the use of the virtual environment is causing me to include all the path info before the entry point call, which in my view really destroys the simplicity an entry point is supposed to provide to the consumer of a script. Is there a way to get setuptools to register the entry point system-wide so that I can call the entry point without the path like this?:
my_DESIRED_batch_file.command
#!/bin/bash
cd "$(dirname "$0")" # set the working directory as the command file locations
entry_point_name <my script args>
Without this complication introduced by the virtual environments, a console script entry point lets the script consumer use a script without having to know where the script is installed or even what language it's written in. I'd like to preserve this simplicity even when packaging in virtual environments.
What I've tried -
I located the actual entry point file in the virtual environment after installing the package:
/anaconda3/envs/my_env/bin/my_entry_name
and placed a copy of this file in the main bin path:
/anaconda3/bin/my_entry_name
and found that I can then call the entry point without the path, as desired, however this is a manual step I don't want to make script consumers to do. Is there a way to get setuptools to place the entry point file in the general bin path rather than the environment bin or some other automatic means to this end?
My setup
OS: macOS Catalina
Shell: bash (yes, I changed it back after Catalina update and suppressed the nagging 'zsh is now default' message)
IDE: PyCharm 19.1 Pro
Anaconda: 4.4.7 (note: was moved from root to User/my_user/ by Catalina update)
Python: 3.7
Virtual env type: conda
Looks like conda run could help.
I can't test it, but looks like it could allow to write a much simpler shell script. Something like that:
#!/usr/bin/env sh
conda run -n ENV my_entry_name "$#"
Seems to be an experimental feature though.