Tuesday, February 1, 2022

[SOLVED] Can't start vitualenv outside of python project

Issue

I was working with my project and virtualenv together and read someplace that this isn't the best practice along with it mucked up my git repo.

Now I have cleaned my project folder (pyHoliday) and updated the gitignore file. Purged the system and started fresh doing:

  1. create a folder to hold the env and project files (pyHoliday/): mkdir Documents/dev/pyHoliday
  2. cd to pyHoliday/: cd pyholiday
  3. clone the pyHoliday python files into pyHoliday/: git clone https://github.com/LanceGundersen/pyHoliday.git
  4. create python3 vituralenv: virtualenv -p python3 env
  5. enable env virtualenv: source env/bin/activate
  6. cd to python project: cd pyHoliday
  7. install requirements: pip install -r requirements.txt
  8. install project: python setup.py install -> Get a warning running install_lib warning: install_lib: 'build/lib' does not exist -- no Python modules to install
  9. Try to run the project: holiday Traceback (most recent call last): File "/home/lance/Documents/dev/pyHoliday/env/bin/holiday", line 6, in <module> from pyHoliday.pyHoliday import run ImportError: No module named 'pyHoliday' Any clue what is going wrong here?

Thanks in advance!


Solution

In you repository pyHoliday is not a package but a pyHoliday.py module, so you shouldn't declare it as a package but as an item in py_modules (in setup.cfg):

py_modules =
    pyHoliday

On the other hand you need to declare programs as a package.

List site-packages/ in your virtual environment to see what is and what isn't installed.



Answered By - phd
Answer Checked By - Candace Johnson (WPSolving Volunteer)