How to access CLI from installed Pip/Python venv script - python

I'm sorry if this is a basic question, but I'm hoping someone can clarify something that may be quite simple.
What I want is to use the tool eyeD3 which is a CLI. The confusing bit is that on the install page it says it should be installed with Pip. Thus, I created a virtual environment and installed the package there.
Okay great, but how do I actually use it now? Because every instruction says to use it as a command line tool. But if it's installed as a pip package then the "eyed3" command is not magically going to be placed in my PATH to be used as intended. So what am I not getting here?
Alternatively I may just download it using sudo dnf install python-eyed3 which should work.
But I really want to educate myself if I'm understanding something wrong, so I can better understand and utilize pip and virtual environments with Python.

Related

python can't find module 'python-for-android'

I am trying to compile my python program into an android APK file. I installed the package 'python-for-android'. when i tried to use it, i go an error saying C:\Program Files\Python39\python.exe: No module named python-for-android. Can someone please tell me what is going wrong?
https://pypi.org/project/python-for-android/
It looks like it is being installed into a different location than where you pip installed the library. If you can give more details about how you installed the package, it might help identify the issue.
Is it possible that you have two python versions, and it installed it into the wrong version.
Using virtual environments might make it easier to understand what is going on. If you pip install into a virtual environment, you can be pretty confident that it is installing into the correct version of python.

Install new python version using virtual venv in linux

I know there are some solutions in the internet but I couldn't find an end to end solution and I am pretty skeptical about doing things wrong so asking here for a complete solution.
I have recently installed debian10 and it comes with python2.7 and python3.7. I want to install python3.6 but not as a new python but as an isolated one using virtualenv (that I got from internet as I have python3.7 and venv can only install the same python version).
I couldn't understand that do I need to install python3.6 first in my system and then use virtualenv or I can directly install virtualenv using pip3 (I prefer pip) of python3 and install it. Also in either of the cases do I need to somehow fetch the source code for python3.6 and if yes then do I need to build it locally first then use virtualenv or not. A detailed step wise solution will be better along with if any changes need to done in the .bashrc file.
I am new in Linux and python environment and still learning. Any help will be appreciated.
Thanks in advance.
P.S.: If you find that I need to explain more or you need some clarifications kindly comment it instead of down voting first. I will try my best to modify my question accordingly.

Do others need to have the same modules installed to run my code in Python?

If I use a module such as tkinter, would somebody need to have that module installed as well in order for my code to run on their machine?
Definitely. You can use virtual environments or containers to deliver required packages or have a requrements.txt or similar to install the dependencies.
python comes with a number of standard modules pre-installed, if the other person is running python (the same version of you) then he/she won't need to install anything, it will just work, that's the case of tkinter. But if you use external packages that you installed to run your code, for example celery, then he/she will need to do the same thing.
If you gave your code to someone to run, they would need to download the same modules, unless you also sent the environment too. The only way I know around this is to freeze your code where you would create an executable. I've used cx_Freeze and pyInstaller and haven't had any issues but it also depends on your needs. You can find some more information through here:
https://docs.python-guide.org/shipping/freezing/
Hope this helps!
In your running environment do a, this file you add to your repo
pip freeze > requirements.txt
When people clone your repo, they only have to do a:
pip install -r requirements.txt
and they will install exactly the same pypi modules you have.
With virtualenv you can isolate a python environment to each project, with pyenv you can use different pythonversions withing the various environment also.

Running pip3 on MacOS Sierra (Python newbie) - do I need a virtualenv?

I'm running MacOS Sierra 10.12.6
By default the system came with Python 2.7.10
I installed Python 3.6.3 (with IDLE) so I can learn Python (3). I understand that this is normal as MacOS may rely on Python 2.x for some programs. Either way, Python3 runs just fine if I run python3 from the command line/terminal, or if I use IDLE (which defaults to Python 3).
Now I want to install some libraries like Beautiful Soup.
And I believe I can install it as follows:
pip3 install beautifulsoup4
which should automatically install it. However, I read that it's recommended to use virtualenv on Mac BEFORE I run the above command. As a newbie, I don't want to mess anything up on my PC, so can anyone point me out how I can do this correctly?
For example, I can follow this link: http://sourabhbajaj.com/mac-setup/Python/virtualenv.html
But I just want to write here to make sure I'm following the right article/commands before I do it. Just being super careful!
Also, can I make a folder with my "virtual environment" and then add sub-folders inside that for each project? Meaning, I don't need to do this everytime, I have one virtual environment and any project that I do just is a subfolder within that space so I can use any libraries that I installed. Just trying to grasp the concept.
Thanks!
Sorry to add confusion.. this can be a tough subject for someone starting out.
The official docs recommend venv, which is similar to, but slightly different than virtualenv.
I would strongly recommend pycharm. It will create your venv for you as part of your project, which you might find helpful.
[Edit: Some other virtual environment features of pycharm that will help you].
If you type in an import statement for a package that isn't installed, it will offer to install it for you.
typing alt-F12 will bring you up a console with your virtual environment active
It syncs up your requirements.txt document for you
It manages your virtual environment path for you (as long as you are running inside pycharm), helping avoid import problems that many newcomers have with virtual environments.
I am not affiliated with pycharm, btw -- I just think it is a great tool for python developers, especially for newcomers, and its treatment of virtual environments is especially helpful.
You create one virtualenv for each project as a way of keeping track of the specific dependencies to keep them minimal which then makes it easier when you want to share projects with other people.
But this is not something you need. No harm comes from installing packages in your real environment as well. So you can safely run
pip3 install beautifulsoup4

Getting a python module to work with Python after installing module (and not re-installing python)

I suppose this would apply to anyone using tools like: virtualenv, virtualenvwrapper, pythonbrew, pyenv, etc.
Let me give the use-case. I am using pythonbrew. I want to create a venv, but I get an Import Error saying that there is no "zlib".
So what I do is, I run this command (linux deb/ubuntu terminal):
sudo apt-get install zlib1g-dev
Now the only way I am aware of making sure that the python version I wanted to use with zlib will now work is to uninstall it and then reinstall it again (for anybody that wishes to know, it now works with zlib being recognized).
This takes a lot of time (installing) and makes me wonder what might happen if I have like 5 venvs with multiple setups, only to realize that I need some new module and have to delete my python version again (to reinstall it) and which may also break the 5 venvs (it may, but I'm not sure).
My question is, how could I make sure that the python version will acknowledge something like the zlib installation above without doing a complete re-install of python?
Is there something I could modify in any of the files or perhaps run some update command?

Categories