can not create requirements.txt file - python-3.x

i have a virtualenv called alpha but after upgrading my ubuntu 18 to ubuntu 19, now i cant install any python package into my virtualenv, basically i cant use pip3 command. whenever i use pip3 command i got this error: ImportError: cannot import name 'dist' (i have tried: sudo apt install python3-dist-utils but its not working). Now because i cant use pip3 command i cant create requirements.txt file. i want to remove my old alpha virtualenv and want to install new one and install all the dependencies using requirements.txt file, but i can't do that because i can't create requirements.txt. How do i solve this problem ?
Edit
Because i have so many libraries installed in my virtualenv(i cant even remember them). first i want to recover all the dependency information's and then want to install new one. I CANT JUST REMOVE THE VIRTUALENV FIRST.

There's no package like dist-utils, you are looking for python3-dist-utils.

Related

pip : how can I change the environment?

I am attempting to solve an issue I am having with pip
The context is as follows : I receive a docker image from a service in my company but I do not have the possibility to change it at all ( it comes as it is and that's it )
The image comes with a few packages already installed but are causing a conflict with the requirement.txt file I would like to use. I can obviously check the environment of the docker image and manually check for all of the pakages one by one but it not very efficient
Is there a way that I can install my requirement.txt in a way were it would take precedence over what is already installed ?
As an exemple, if I have ABC==1.4.21 already installed but I would like to have ABC==2.3 would it be possible to get pip to install the version in the requirement.txt ( the opposite is also possible ) ?
I already did attempt to unistall the previously installed packages with pip freeze | xargs pip uninstall -y but I am having issues with some of the packages such as conda : ERROR: Cannot uninstall 'conda'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
Any help is much appreciated

I have completely messed up my Python Env and need help to start fresh

Long story short, I messed with my Python environment too much (moving files around, creating new folders, trying to reinstall packages, deleting files etc.) My google package doesn't work anymore. Everytime I try to import the package, it says it can't find the module, even though I did a pip install.
I was wondering how I could do a hard reset/delete python off my computer and reinstall it.
Thanks.
is your pip working try extracting the required modules.
pip freeze > requirements.txt
create new Venv
pip install -r requirements.txt
I figured it out. My pip was installing to a site packages folder inside a local folder, while my jupyter notebook was trying to pull from the anaconda site packages folder.

Socketio installing problems

I'm facing a problem with socketio. I imported it into my programme by command:
import socketio
Wen I typped pip freeze I got:
python-socketio==4.5.1
Then I ran programme by typing into console:
myfile.py --mode "mode"
But it says:
ModuleNotFoundError: No module named 'socketio'
Any ideas how to fix it?
It happens when you have multiple version of pip install on your system.
you can deal with this problem by creating a virtual environment and again loading the socket-io library.
Install pipenv.
pip install pipenv
Then change directory to the folder containing your Python project and initiate Pipenv,
cd your_project
pipenv install
This will build two new files in your project directory, Pipfile and Pipfile.lock, and a new virtual environment for your project, if it doesn't already exist. If you add the —two or —three flags to the last command above, your project will be initialized with the use of Python 2 or 3. Otherwise, Python's default version will be included.
To install a Python package for your project use the install keyword. For example,
pipenv install beautifulsoup4
and for uninstalling
pipenv uninstall beautifulsoup4

Pip on only installs to python27 while i need it to install on python37

I have multiple instances of python in my computer namely python27, python3.6 and python 3.7.
The import module for docx worked daily on python27 until suddenly it stopped working today. I tried installing the module again using pip in windows command line.
It says only installed in python27 directory. But there's an
importError on my script.
I guess I should be high time i transferred into python37 but I can't seem to make pip install into python 3.7
Can someone offer some advice as to the messy situation I'm in?I want to transfer to python3 and install docx in python3
Already checked modules using pip and docx is not there.
You should try setting your command prompt on the version of Python you want the module to install. Then, just use "pip", to install.
This is how you can do this:
Go into File Explorer (hopefully you have windows) and press and hold the shift key, then right click the folder that you want command prompt to look at. In this case, the folder with the version of Python. Then you click on the command prompt selection, and you're golden. Just use "pip install xyz" from there on. Glad to help
- BURAK ILOGLU
for python 3 try below given approaches.
sudo apt-get install python3-pip
this should get you pip3 and you can use pip3 to install packages specific to python3
and also
python3 -m pip install <package name>

Can I create a virtualenv after making the mistake of installing all project packages globally?

So I am a python newb like first project ever newb. I jumped right in disregarding virtualenv and installed everything globally. Now I need to be able to share my project with other team members.
Can I create a virtualenv after making the mistake of installing all project packages globally?
I am using python 3. I've read these links:
pip installing in global site-packages instead of virtualenv
How to import a globally installed package to virtualenv folder
But I don't think thats what Im looking for. I want to go the requirements.txt route I think.
Any guidance or suggestions?
Yes, you can create a virtual env.
You can create a requirements.txt file for the packages you installed globally.
pip3 freeze > requirements.txt
and then you can use this requirements file for installing all the packages in the virtual env which will be isolated from your global environment.
First you need to install virtualenv:
pip3 install virtualenv
Create a new virtual env using the following command:
virtualenv -p python3 envname
You can activate the virtualenv by:
source /path/to/new/virtual/environment/bin/activate
To deactivate the environment and return to your local environment just run:
deactivate
Install the requirements from the file.
cat requirements.txt | xargs -n 1 pip3 install
This should install all your packages in the virtual environment.
To check which python you are using use which python command and to check installed packages use pip3 list
I hope this will clear your doubt.

Resources